function onTouched(hit)
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
print("Disabled Movement")
Controls:Disable()
local human = hit.Parent:findFirstChild("Humanoid")
if human then
local anim = human:LoadAnimation(script.Parent.Animation)
anim:Play()
wait(1)
Controls:Enable()
print("Enabled Movement")
end
end
script.Parent.Touched:connect(onTouched)
print("Working Script!")
Iâm tryna make it so if I touch a part I stop moving and I do a animation then I be able to move again (Just like transfurmation, I just wanna make a test) But the script wont work. No errors.
I think you are putting too much effort into stopping movement, you can just anchor HumanoidRootPart to make the player unable to move or jump, thatâs what I do at least.
function onTouched(hit)
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
print("Disabled Movement")
Controls:Disable()
if hit.Parent:FindFirstChild("Humanoid") then
local human = hit.Parent.Humanoid
local anim = human:LoadAnimation(script.Parent.Animation)
anim:Play()
wait(1)
Controls:Enable()
print("Enabled Movement")
end
end
script.Parent.Touched:connect(onTouched)
print("Working Script!")
Is this a local script that you put in the Workspace?
In that case, local scripts do not run in Workspace.
You need to use RemoteEvents to communicate the server script placed in the Workspace to a localscript placed either StarterPacks/StarterPlayerScripts/StarterGui or so.
I am currently working with a script that requires to play an animation while your character is stopped. I anchored the Humanoidâs RootPart and the animation works perfectly fine.
Try this and put the animation in the script and the script into the part.
local Animation = script.Animation --Replace Animation (script.Animation) with the name of the Animation object
script.Parent.Touched:Connect(function(touched)
if touched.Parent:FindFirstChild("Humanoid") then
local AnimPlay = touched.Parent.Humanoid:LoadAnimation(Animation)
touched.Parent.HumanoidRootPart.Anchored = true
AnimPlay:Play()
AnimPlay.Stopped:wait() --Waits until it finished playing
touched.Parent.HumanoidRootPart.Anchored = false
end
end)
The good news is I managed to fix it!!
the help of @nLocaI and @slothfulGuy!
The bad news is when I touch the part and do the animation it repeats the animation because Iâm still on it touching it. how can I make it so if I touch it and I try touching it again it wont work?