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

Teleportation CFrame script not showing errors works in studio but not online why?

This script teleports you to the part that is named 1,2,3,4,5,6,7 etc.. It teleports you depending on your PlayerStat Value Named "Stage"

Not sure at all where the problem is!

script.Parent.Touched:connect(function()
	local player = game.Players.LocalPlayer
	local Stat = player:WaitForChild("PlayerStats")
	local spot = game.Workspace:FindFirstChild(Stat.Stage.Value)

			player.Character.Torso.CFrame = spot.CFrame + Vector3.new(0,3,0)
end)

1 answer

✓ Accepted answer

LocalScripts don't work in workspace, and Scripts can't use LocalPlayer

This works in studio because everything is ran on the client. However, in an actual game this is not the case.

Read this article for more information

Finding the player

To get the player, I'll be using the GetPlayerFromCharacter function of the Players Service.

We'll give the function the part's parent, and if it isn't a character, it will not error, but return nil.

-- Regular Script
script.Parent.Touched:connect(function(p)
	local player = game.Players:GetPlayerFromCharacter(p.Parent)
	if player then
		local Stat = player:WaitForChild("PlayerStats")
		local spot = game.Workspace:FindFirstChild(Stat.Stage.Value)
		player.Character.Torso.CFrame = spot.CFrame + Vector3.new(0,3,0)
	end
end)

Good Luck

If I helped, please don't forget to accept my answer.

1 comment

0

I knew it had something to with local but i did not know how to fix thank you!

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