local Hit = game.Workspace.Model.Hit local L1 = game.Workspace.Model.L1 local End = game.Workspace.Model.End function onTouched(hit) if hit.Parent:FindFirstChild("Humanoid") then --check if the part is part of the humanoid's body local character = hit.Parent --character (player model on the workspace) local humanoid = character:WaitForChild("Humanoid") --humanoid found inside the player's character humanoid:MoveTo(L1.Position) end end script.Parent.Touched:connect(onTouched)
So all i want to do is that during this script running the player can not imput any movement controls from the keyboard whilst the script is running. Basically disable it till its done.
Problem
You want to disable the character's movement abilities until it's done
Solution
A humanoid has the option in the properties bar to change movement and such. Add this to the script:
humanoid.Walkspeed = 0 humanoid.JumpPower = 0 wait(1)
and this after:
wait(1) humanoid.Walkspeed = 16 humanoid.JumpPower = 50
This'll wait for one second before TPing the player and it'll freeze the player for 2 seconds.
Final Script
local Hit = game.Workspace.Model.Hit local L1 = game.Workspace.Model.L1 local End = game.Workspace.Model.End function onTouched(hit) if hit.Parent:FindFirstChild("Humanoid") then local character = hit.Parent local humanoid = character:WaitForChild("Humanoid") humanoid.Walkspeed = 0 humanoid.JumpPower = 0 wait(1) humanoid:MoveTo(L1.Position) wait(1) humanoid.Walkspeed = 16 humanoid.JumpPower = 50 end end script.Parent.Touched:connect(onTouched)
Suggestions
I recommend using CFrames rather than humanoid:MoveTo
, and also changing game.Workspace to simply "workspace". With following these suggestions, THIS would be the final script:
local Hit = workspace.Model.Hit local L1 = workspace.Model.L1 local End = workspace.Model.End function onTouched(hit) if hit.Parent:FindFirstChild("Humanoid") then local character = hit.Parent local torso = character.Torso local humanoid = character:WaitForChild("Humanoid") humanoid.Walkspeed = 0 humanoid.JumpPower = 0 wait(1) torso.CFrame = CFrame.new(L1.Position) wait(1) humanoid.Walkspeed = 16 humanoid.JumpPower = 50 end end script.Parent.Touched:connect(onTouched)
If this helped you, be sure to accept my answer! It helps both of us!
Locked by youtubemasterWOW and zblox164
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?