Hello! I created a local script for checkpoints, but for some reason it does not work locally. What could be the problem?
local player= game:WaitForChild("Players").LocalPlayer
local character = player.Character
local CheckpointData = script.CheckpointData
local CheckpointValue = script.CheckpointData.CheckpointValue
for i, v in pairs(game.Workspace.CheckpointFolder:GetChildren()) do
if v:IsA("Part") then
function onTouch()
CheckpointValue.Value=v.Position
end
end
v.Touched:connect(onTouch)
end
end
for i, v in pairs(game.Workspace.Obby.KillPart:GetChildren()) do
if v.Name == "KillPart" then
function onTouch()
player.Character:MoveTo(CheckpointValue.Value)
end
end
end
v.Touched:connect(onTouch)
end

could you elaborate on which part isn’t working locally?
Question, why are you running/controlling this on the client?
When a player teleports to a checkpoint, all players teleport to the checkpoint
I wanted to improve this system with visual effects, which is easier to do on a local script
Any errors? Also, I don’t think game:WaitForChild("Players") will work, instead it should be game:GetService("Players")
I suggest running it on the server, then firing remotes to the client for visual effects, exploiters can easily abuse all this if its on the client
Also, you should probably put it in StarterPlayerScripts, I believe theres moments where StarterGui scripts wont run
so basically your touch function needs to check whether the player touched the part, as right now you’re checking if any player touches the kill brick, which results in everyone getting teleported back.
consider using this as your ontouch function -
function onTouch(part)
if game.Players:GetPlayerFromCharacter(part.Parent) == player then
player.Character:MoveTo(CheckpointValue.Value)
end
end
end
end
v.Touched:connect(onTouch)
1 Like
It’s on the client though. It only detects when the local player touches it and is only able to move the local player
yea, but look, the function checks if anything (or any player) touches the part and then teleports the owner of the local script back. So basically, every time someone touches that part, everyone who has the on touch event has their script fire, which teleports them back.
Ohhh mb, didn’t see that part lol
1 Like