Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

?math.random and player name error

local playerName = game.Players.LocalPlayer.Name

game.Players.PlayerAdded:Connect(function()
	local rand = math.random(1,2,3,4)
	if game.Workspace.Signs["Sign"..rand].SurfaceGui.TextLabel.Text == "Empty House" then
		game.Workspace.Signs["Sign"..rand].SurfaceGui.TextLabel.Text = playerName.."'s House"
	elseif game.Workspace.Signs["Sign"..rand].SurfaceGui.TextLabel.Text ~= "Empty House" then
		repeat place = math.random(1,2,3,4)
			
		until game.Workspace.Signs["Sign"..rand].SurfaceGui.TextLabel.Text == "Empty House"
		if game.Workspace.Signs["Sign"..rand].SurfaceGui.TextLabel.Text == "Empty House" then
			game.Workspace.Signs["Sign"..rand].SurfaceGui.TextLabel.Text = playerName.."'s House"
		end
	end
end)

This is a LocalScript that I made for house owning. So basicly if your first join this server It get's the name and do math.random for choosing a random house, and in the house sign, it will say "PlayerName's House" But it doesn't work.

1 comment

0

Your math is going to produce the same number every time the script runs. Look into math.randomseed. Also it may be easier to add a stringvalue inside the part and check it’s value.

1 answer

✓ Accepted answer

I believe that this might be the problem.

local rand = math.random(1,2,3,4)

repeat place = math.random(1,2,3,4)

math.random must two have to numbers and not more than that(If I'm not wrong). So this two codes should fix your problem. Just change the two codes above with this bottom one.

local rand = math.random(1,4)

repeat place = math.random(1,4)

This way the script will pick the number from 1 to 4(Inclusive) Hopefully this helps you. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.