#My animation doesnt work in my local script...
1 messages · Page 1 of 1 (latest)
So for local character i would set it to be
local character = player.character or player.CharacterAdded:Wait()
Also I want to warn you. Making a value bigger in a localscript wont change it on the whole server, but only for the player that the script runs on.
Yeah thats okay
Nevermind you dont have to do this in a localscript
For tools you should use global scripts
Basically, when a player holds a tool, his parent will be the character.
So if you want to get the player from a character, you would use game.Players:GetPlayerFromCharacter(tool.Parent)
where tool is just the path of the tool obviously
First of all, it has to be a global script
So a normal script
Then you want to set the player to be the thing i showed you here
Careful though, when you execute the script and the player does not hold the tool in his hand, the tool wont be in the character directly. He is in the characters backpack then
So i would put player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) inside of the .Equipped event
So it gets the player once he actually holds the item
What have you done so far?
You can use
```lua
Nono
The lines are important
Also you need these: `
Test
Good now just paste your code
Did you make 3 of them?
Of these bois `
Or maybe its just formatted weirdly on phone idk
Now you do exaxtly what you had before
Just that you get the character and everything after the player obviously
Imma shower really quick so dont wonder why i wont answer
back
basically you can make it like you had it before, just with the changes i told you
** You are now Level 6! **
so what is the code now?
** You are now Level 4! **
local player = game.Players.LocalPlayer -- the player that the local script is running for
local character = player.Character
local animation = script.Parent:FindFirstChild("Animation")
local stickClickAnimation = character.Humanoid:LoadAnimation(animation)
script.Parent.Equipped:Connect(function(mouse) -- when the tool is equipped...
mouse.Button1Down:Connect(function() -- when mouse button is clicked down...
stickClickAnimation:Play()
player.leaderstats.Melee.Value += 1 -- adds one onto the players leaderstats
end)
end)
this was the old code
yes you need the same stuff in a global script iwth some changes
alright
you dont need the game.Players.LocalPlayer
its in a local script that wont work
and the character and the stickClickAnimation should be after the player inside the tool.Equipped
by the way i recommend putting the local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) inside of tool.Equipped not inside mouse.Button1Down because you dont need to get the player every time you click.
also the character and stickClickAnimation can go after the player
not inside of the button1down
looks about good then. you dont have to define tool if youre not going to use it btw. i would use it though
just replace every script.Parent with tool
wait a second
okay i would start debugging at this point. do you know what that is?
basically using prints to know what code does get executed and what code doesn't
in a global script, right?
hmm okay
yes. just put a print("test") inside of the tool.Equipped and equip the tool
yes exactly
now you see, theres a problem with the mouse.Button1Down
lemme tell you one thing
i just noticed
thats not how you use tools xD
you can use a separate event called .Activate
i think
and that is the one that happens when you left click
because you dont need that
.Activated event is basically already the left click
on the tool
gg
nice
np <3
TheDevKing
now i basically only use the roblox documentation
yeah?
lemme guess: you can spam it
alright
you need something called a debounce then
cooldown for the animation time
thats basically a variable that doesn't allow the player to use the tool again
after the animation you can just set it to false again and its usable agin
or that
wait Vamp does playing animations yield?
not quite
[object Object]
you need an if statement
if debounce == false then
debounce = true
stickClickAnimation:Play()
end
debounce = false
and since animations dont yield
you have to use a wait with the length of the animation (i would personally add a bit more time to the wait so you have a cooldown)
also after your done can you check dms @remote aspen
yes thats correct
yes you could name it whatever you want
its just a variable
but scripters call it a debounce its just the type of variable you use in that case
** You are now Level 5! **
because you didnt add the wait
playing animations doesnt yield
that means
yielding means that it waits until the function is finished before it continues
in this case it doesnt yield. the code goes on even though the animation is playing
so you need a wait(length of the animation) after playing the animation
is the animation 1s?
just click on the animation in the explorer. you can see the length somewhere in the properties
and also put the leaderstats thing into the debounce thing
otherwise they can spam and get points
nonono i dont think
local tool = script.Parent
local animation = script.Parent:FindFirstChild("Animation")
local debounce = false
tool.Activated:Connect(function(mouse) -- when the tool is equipped...
local player = game.Players:GetPlayerFromCharacter(tool.Parent) -- gets the player from the character bercause whatever the parent of the tool is, is the player.
local character = player.Character
local stickClickAnimation = character.Humanoid:LoadAnimation(animation)
if debounce == false then
debounce = true
stickClickAnimation:Play()
player.leaderstats.Melee.Value += 1 -- adds one onto the players leaderstats
wait(1)
end
debounce = false
end)
that shouldnt work now...
i mean
it shouldnt be spammable
sorry
it has to
click on the animation in the explorer
then it should say Length somewhere
hmm true
just set the wait duration to stickClickAnimation.Length
i think that should work
yes thats a good idea xD
AH
im an idiot sorry
this boy is making trouble
because its not in the if
it runs it even if the debounce is set to true
you have to put it inside
because when you activate the tool it always gets set to false and then the animation automatically can get played again
** You are now Level 7! **
see what i mean?
gg
nice
6h for that?! xD
hahahaha
you're learning. so its good xD
i really recommend starting to learn it actually
like taking your time to learn it, not while making a game
scripting in roblox
you can always ask me in my dms if you want :)
ahh good.
didn't he cover debounce in the basic guide?
ah okay.
alr i wish you best of luck for learning and have a good day
yes obviously, i probably wont even see it when you ask me here
you're welcome