Jersey Random Number Selector

What do you want to achieve?
I am trying to make it so that when the player spawns in, the Text on their back changes to a random number, but so that everyone can see it.

What is the issue?
Below this is my code. Right now, it is in the “StarterCharacter”. If the StarterCharacter is in workspace, the code works, but when I put it in StarterPlayer, it does not work, and gives me no errors.

local character = script.Parent
local NumberPart = character.Number
local Number = NumberPart.SurfaceGui.Number

function play()
	local JerseyNumber = math.random(1, 100)
	print(JerseyNumber)
	Number.Text = JerseyNumber
end

What solutions have you tried so far?
Putting it in a LocalScript, it didn’t work.

Right now the script is INSIDE the StarterCharacter, and it is a normal Script, not a LocalScript.

2 Likes

Simple use PlayerAdded function to do this:

ServerScriptService


game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local NumberPart = character.Number
		local Number = NumberPart.SurfaceGui.Number

		function play()
			local JerseyNumber = math.random(1, 100)
			print(JerseyNumber)
			Number.Text = JerseyNumber
		end
	end)
end)
1 Like

It should be a Server Script:

game.Players.PlayerAdded:Connect(function(player)

local character = player.Character
local numberPart = character.Number
local number = numberPart.SurfaceGui.Number

	local jerseyNumber = math.random(1,100)
	print(jerseyNumber)
	number.Text = JerseyNumber

end)
2 Likes

Hey @Qd_awg i have made a better version of your script when everytime you click it picks a number

local Player = game:GetService("Players").LocalPlayer

local mouse = Player:GetMouse()

local TextLaber = script.Parent.ScreenGui.Frame.TextLabel  -- customize this to your textlabel

mouse.Button1Up:Connect(function()
	local JerseyNumber = math.random(1, 100)
	print(JerseyNumber)
	TextLaber.Text = JerseyNumber
end)

2 Likes

This local script was in StarterGui

2 Likes

He wants it to be server-sided so everyone can see the number.

1 Like

Thank you so much! I’m not really a scripter, so I have troubles sometimes, thanks!

No problem! Hope your game comes along well!

1 Like