Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

?math.random and player name error

Asked by 6 years ago
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.

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. ABK2017 406 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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. :)

Ad

Answer this question