✓ Accepted answer
Hey man, welcome to Scripting Helpers.
I've got a few things about your script to point out and explain, so bear with me. If you really wanna learn how to script though, this will definitely help.
First off, you're using a local script to get the player, which is all fine and good, except that local scripts don't run anywhere outside of the client. Crazy right!
Basically, the local script only runs inside of places like StarterPlayerScripts, StarterGui, StarterPack, and StarterCharacterScripts. What do these places all have in common? Access to the local client (Our player). The script needs some sort of access to the local client to run, as these scripts only run for the local player.
Next, the touched event. The touched event is just a function that fires when something is touched, and returns whatever touched it into the argument "Hit" that you're using.
So, first off, instead of changing the LocalPlayers position, we need to change their Character's position. The Player and the Character are actually not the same thing. We can use Hit.Parent to solve that issue. I'll explain it more in the comments on the script.
Debounce = false
script.Parent.Touched:Connect(function (Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if not Debounce then
Debounce = true
Hit.Parent.HumanoidRootPart.CFrame =
CFrame.new(Hit.Parent.HumanoidRootPart.Position - Vector3.new(0 ,0 ,-5))
wait(1)
Debounce = false
end
end
end)
I'm gonna link some useful references, goodluck scripting :) If you have any questions, just leave a comment.
5 comments
Why have it be a local script inside of a part, and have it try to find "LocalPlayer"?
well I don't know any alternatives to game.Players.LocalPlayer...
try something like this: script.Parent.Touched(function(hit) local plr = (hit.Parent) plr.Torso.CFrame = CFrame.new(plr.Torso.CFrame.m-Vector3.new(0,0,-5)) end)
or use R6
Thanks for the help~ Ur script taught me a few things, but sadly didn't work uwu, got some help in the end tho