So, I made a map loading script, and the problem is that the script, is ment to pick one of the 5 maps randomly, it works, the porblem is that it does it too many times, it's only ment to do it once. Well, I know what to do to fix it, I just don't know how... I mean I know I have to use it as a function, not a while wait.. And I know that theres a way to do the function whenever a value changes... I just don't know how! Help?
RoundStart = game.Workspace.RoundStart Room1 = game.ServerStorage.Room1 Room2 = game.ServerStorage.Room2 Room3 = game.ServerStorage.Room3 Room4 = game.ServerStorage.Room4 Room5 = game.ServerStorage.Room5 while wait() do wait(1) if RoundStart.Value == true then RandomRoom = (math.random(5)) if RandomRoom == 1 then Map1 = Room1:Clone() Map1.Parent = game.Workspace end if RandomRoom == 2 then Map1 = Room2:Clone() Map1.Parent = game.Workspace end if RandomRoom == 3 then Map1 = Room3:Clone() Map1.Parent = game.Workspace end if RandomRoom == 4 then Map1 = Room4:Clone() Map1.Parent = game.Workspace end if RandomRoom == 5 then Map1 = Room5:Clone() Map1.Parent = game.Workspace end end end
The reason it isn't picking random number is because you didn't give it a range, which it requires. So do:
RandomRoom = math.random(1,5) or math.random(5)
also I noticed your script says:
while wait() do wait(1)
which isn't necessary, you can just do
while wait() do --or while wait(1) do --the difference is "1" is every second, and () is much faster
NOW TO ANSWER THE MAIN PART OF YOUR QUESTION
To connect when a value changes use
game.Workspace.RoundStart.Changed:connect(function() --do whatever end)