Hey,
So i’m trying to make a script, that if a humanoid touches a specific part, it plays a animation.
Now i’m not sure on how to do so.
Do i need to make a Script inside the brick, which registers the hit and acces the player? Or a Localscript in PlayerScript to register the hit, and if so. Does it then only play localy?
If you’d want everyone (Or the server) to see the animation, you’d do it on a Server Script
but if you want just only you to see it (Client wise), yeah just use a Local Script
It depends on what preference you’re mainly looking for
2 Likes
In this case Server-wide.
script.Parent.Touched:Connect(function(Hit)
if Deb == true then return end
Deb = true
if Hit.Parent:FindFirstChild('Humanoid') then
print('Human')
else
print('Not Human')
end
Deb = false
end)
Right?
You almost had it! All you need to do is find the Humanoid’s Animator
, then play the animation that way:
local Part = --Define your Part here plz
local Deb = false
local AnimationToPlay = --Somewhere, just define this to what animation you want to play
Part.Touched:Connect(function(Hit)
if Deb == true then
return
end
Deb = true
if Hit.Parent:FindFirstChild("Humanoid") then
local Animator = Humanoid:WaitForChild("Animator")
local PlayAnimation = Animator:LoadAnimation(AnimationToPlay)
PlayAnimation:Play()
end
end)
1 Like
Oh yeah another reminder as well, but LocalScripts
can only fire if they’re a part of a descendant of a client service
Examples can be:
-
StarterPack
-
StarterGui
-
Player/CharacterScripts
-
The Character Model
1 Like
Ah, you’re placing the Script inside PlayerScript?
Is it possible to not place it here. As the Parent of the Part changes every round, due different maps.
Ah yeah, since LocalScripts
can only work from the client & not the server side
It depends on where you put the part as well, so you’d need to keep in mind that
1 Like