My friend and I are making a game that has an obby you get to from the lobby for people waiting. The problem is that it won't teleport them back to the lobby and reward them. [IMPORTANT] It works in ROBLOX Studio's "Play". It is a script as a child of a part directly in workspace. I have tried it under a local script in the same location but it still won't work when you play outside of studio.
The script is...
--Made by CamScripted function onTouched(part) local shillings = game.Players.LocalPlayer.leaderstats.Shillings local c = part.Parent if c ~= nil then c.Torso.CFrame = CFrame.new(Vector3.new(19.808, 3.285, 8.748)) end wait(.1) shillings.Value = shillings.Value + 10 wait(1) end script.Parent.Touched:connect(onTouched)
When using LocalPlayer it has to be in a LocalScript, inside a player object or character. To fix this, you just need to check if what touched the part was a player's character and not just any random block. Here's the code you'd need:
--Made by CamScripted, edited by UndeniableLimited :3 function onTouched(part) local shillings -- Create it here so it can be used later local c = part.Parent if c ~= nil and game.Players:FindFirstChild(c.Name) ~= nil then -- If they're a player shillings = game.Players[c.Name].leaderstats.Shillings c.Torso.CFrame = CFrame.new(19.808, 3.285, 8.748) -- Why Vector3 in a CFrame? It's not needed end wait(.1) shillings.Value = shillings.Value + 10 -- Removed a wait from here, it wasn't needed unless you were going to add to it! end script.Parent.Touched:connect(onTouched)