So this goes along with a question that I've previously asked (which has been answered). Here's the script again:
wait(1) character = game.Players:findFirstChild(""..game.Workspace.ValueHold.Player.Value.."") local t = game.Workspace.ValueHold.RoomCount t.Changed:connect(function() print("Changing Room...") local r = math.random(1,3) if r == 1 then local room = game.ServerStorage.defroom1:Clone() room.Parent = game.Workspace game.Workspace.ValueHold.CurrentRoom.Value = 1 character.Character.Torso.CFrame = CFrame.new(game.Workspace.defroom1.spawn.Position) elseif r == 2 then local room2 = game.ServerStorage.defroom2:Clone() room2.Parent = game.Workspace game.Workspace.ValueHold.CurrentRoom.Value = 2 character.Character.Torso.CFrame = CFrame.new(game.Workspace.defroom2.spawn.Position) elseif r == 3 then local room3 = game.ServerStorage.defroom3:Clone() room3.Parent = game.Workspace game.Workspace.ValueHold.CurrentRoom.Value = 3 character.Character.Torso.CFrame = CFrame.new(game.Workspace.defroom3.spawn.Position) end end)
Now, time for me to explain. So, you touch a button, you get teleported to a new room, that room has a button that does the same thing, yadda yadda yadda, nothing important, until you get to the actual teleporting part. So, I have a value that stores the players name upon entering the game. So, if your name is "awesomedude123", then the value changes to "awesomedude123". The beginning of the script defines "character" as "awesomedude123", and when a random room is picked, it takes "character" and teleports him to a new room. Same story as my last problem: Works In test mode, but not in a server. I've been told to add a "wait(1)' before it, and that should fix the problem, but it doesn't.
All help is greatly appreciated.
I recommend using a LocalScript for this.
Turn on FilteringEnabled, and insert a LocalScript into StarterPlayer.StarterPlayerScripts.
This way, you don't need to mess around with values or anything to find out which player to teleport.
Your script might look something like this
repeat wait() until game.Players.LocalPlayer; local player = game.Players.LocalPlayer local character = player:WaitForChild("Character") local rooms = {game.ServerStorage.defroom1, game.ServerStorage.defroom2, game.ServerStorage.defroom3} local buttons = {game.Workspace.button1, game.Workspace.button2, game.Workspace.button3} local currentRoom = {} --The script will put stuff in here local jammed = false --This is for debounce. If a player touches the button, we only want the script to register it once. ----- local seeder = coroutine.create( function() while true do math.randomseed(game.Workspace.Randomparts.a1.Rotation.X or tick()) coroutine.yield() end end) ---- This creates seeds for random numbers so it creates a different random sequence each time! function createRoom(Index) local newRoom = rooms[Index]:Clone() table.insert(currentRoom,newRoom) newRoom.Parent = workspace local button = newRoom:FindFirstChild("Button", true) button.Touched:connect(buttonTouched) end function buttonTouched() --Create a function for each button that fires when the button is touched if not jammed then jammed = true --make sure no more functions can be created coroutine.resume(seeder) local newRoomIndex = math.random(1,#rooms) --pick a random room (could be the same one) print("Changing Room...") --Remove old room currentRoom[1]:Destroy() table.remove(currentRoom,1) --Create new room createRoom(newRoomIndex) character.Torso.CFrame = CFrame.new(rooms[newRoomIndex].spawn.Position) --Teleport player jammed = false --make the sript able to run again end end --Setup-- createRoom(1)