Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animiation LocalScript not working...?

Here's what this looks like: Water ClickDetector --child of water LocalScript -- child of water Animation -- child of LocalScript

What's supposed to happen is when you click the water an animation plays. The animation doesnt play, and no errors in output...

The LocalScript:

player = game.Players.LocalPlayer

animation = script:WaitForChild('Animation') -- the animation is a child of this script
enabled = true
script.Parent.ClickDetector.MouseClick:connect(function()
        if enabled == true then
          enabled = false
          local animationTrack = player.Character.Humanoid:LoadAnimation(animation)
          animationTrack:Play()
          wait(3)
          enabled = true

1 comment

0

If this script isn't inside the player then you can't use LocalPlayer.

1 answer

A LocalScript is only run, when it's parented somewhere in a Player, otherwise it doesn't even run. You'll have to use a different approach, which is not from the "Water" but from the Player.

Put this LocalScript (And the Animation in it) into StarterPlayerScripts (Located in StarterPlayer):

local Range = 20
local Player = game.Players.LocalPlayer --get the local player
local Mouse = Player:GetMouse() --get the mouse
local enabled = true
local animation = script:WaitForChild('Animation')
 
Mouse.Button1Down:connect(function()
	if Mouse.Target ~= nil then --Prevents you from getting errors when you would click in empty space
	if Mouse.Target.Name == "Water" and (mouse.Hit.Position - Player.Character.Torso.Position).magnitude < Range and enabled = true then --Checks if the Part's name is Water and if it's in range and if it's enabled.
          local animationTrack = player.Character.Humanoid:LoadAnimation(animation)
          animationTrack:Play()
          wait(3)
          enabled = true
	end
	end
end)

I might have made some mistakes, so correct me, if it doesn't work, then contact me, I'll see if I can fix it.

Btw, StarterPlayScripts automatically insert the script in the player, when he joins the game.

P. S. Please UpVote, I need better rating! ;D

3 comments

0

Im a little confused on line 9. What is the p there, and why does the line go down? I'm just confused. Do I put mouse.p.Player.Charcter.Torso.Position).magnitude < Range and enabled = true then ?

0

Also P is not a valid member of PlayerMouse. And nothing happens.

0

Ah sorry, made a little mistake, check it now.

This discussion is preserved as it was. New answers, comments, and votes are closed.