Text must be unicode or bytes error

import pygame
pygame.init()
import math


running = True
windowHeight = 500
windowWidth = 500
window = pygame.display.set_mode((windowHeight, windowWidth))
clock = pygame.time.Clock()
score = 0
smiley = pygame.image.load("smiley.png")
smiley = pygame.transform.scale(smiley,(120,120))
font = pygame.font.Font('Extra Blue.ttf', 26)

stillCirclePos = [250,250]
stillCircleSize = 60
stillCircleColour = (0,0,0)

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            print(mousePos)
            if distance < stillCircleSize:
                score += 1
                print(score)
    mousePos = pygame.mouse.get_pos()
    window.fill((255,255,255))
    #print(mousePos)


    distance = math.sqrt( ((mousePos[0]-stillCirclePos[0])**2)+((mousePos[1]-stillCirclePos[1])**2))
    scoreDisplay = "Points:", score

    renderedText = font.render(scoreDisplay, 1, pygame.Color("red"))

    window.blit(renderedText, (50,50))




    pygame.draw.circle(window, stillCircleColour, stillCirclePos, stillCircleSize)
    window.blit(smiley, (190,190))




    pygame.display.flip()
    clock.tick(60)


pygame.quit

Whenever I try to run this code, it says “TypeError: text must be a unicode or bytes”. How do I prevent this from happening, while making the text display the score?

Hello,

it appears that you have not defined (assigned a value to) the word distance prior to it being used here:

To test this, assign it a default value.

I’m guessing the error is somewhere around here:

    scoreDisplay = "Points:", score

    renderedText = font.render(scoreDisplay, 1, pygame.Color("red"))

scoreDisplay is currently defined the same way you would use it in a print statement, which in this case is as a tuple of a string and an integer.
The render method may expect its first argument to be a string (or bytes, as the error message says).
If so, you could fix this by changing it to

    scoreDisplay = f"Points: {score}" 

or any other way to turn this into a string.

A lot of the info I’m guessing about is actually in the full text of the traceback (i.e, the line the error occurs and the statement that was executed). So while I thank you for mentioning the actual error message, next time please copy/paste the entire thing

Thanks, this worked!

And thanks again for the tip about the error.