Hello! Im trying to make a sword but it wont work, theirs no error in the output but here’s the script!
local plr = game.Players.LocalPlayer
local Slash1 = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Slash1"))
local Slash2 = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Slash2"))
local Slash3 = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Slash3"))
local num = 1
script.Parent.Equipped:Connect(function()
Slash1:Play()
end)
script.Parent.Equipped:Connect(function()
Slash1:Stop()
end)
script.Parent.Activated:Connect(function()
if num == 1 then
Slash1:Play()
script.Parent.RemoteEvent:FireServer()
elseif
Slash2:Play() then
else
Slash3:Play()
end
end)
Okay you dont update the num variable. You need to add or subtract values to the variable num for the following if statements to be ran through when the tool is activated. Also, you have a random then after Slash2:Play() which is interesting, I would recommend removing that so it doesn’t error. Another thing, you should copy and paste your script.Parent.RemoteEvent:FireServer() code where it will happen each time you click instead of only activating when num == 1.
Instead of doing multiple if statements use a table with the loaded tracks
I’d recommend to wait for the character to load
Your only firing the remote once
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local slash1 = script:WaitForChild("Slash1")
local slash2 = script:WaitForChild("Slash2")
local slash3 = script:WaitForChild("Slash3")
local tracks = {
humanoid:LoadAnimation(slash1),
humanoid:LoadAnimation(slash2),
humanoid:LoadAnimation(slash3)
}
script.Parent.Equipped:Connect(function()
tracks[1]:Play()
end)
script.Parent.Activated:Connect(function()
local num = math.random(1, 3)
tracks[num]:Play()
script.Parent.RemoteEvent:FireServer()
end)
Go back to the animation editor and set its animation priority to Action, that way it will play over anything else. Then export it over the pre-existing animation. (Do that with all the slash animations)