So I tried making a bat and it has animations, but for some reason the animations are not playing. The damage and sound works its just the animations. any help?
here is the script
local player = game.Players.LocalPlayer
local debris = game.Debris
local canattack = true
local attacking = false
wait()
local char = workspace[player.Name]
local holster = char.Humanoid:LoadAnimation(script.Parent.holding)
script.Parent.Equipped:Connect(function()
holster:Play()
end)
script.Parent.Unequipped:Connect(function()
holster:Stop()
end)
script.Parent.Activated:Connect(function()
if canattack == true then
local attack = char.Humanoid:LoadAnimation(script.Parent.attacking)
attack:Play()
local sound = Instance.new("Sound",script.Parent.Handle)
sound.SoundId = 'rbxassetid://541909814'
sound:Play()
debris:AddItem(sound,1)
canattack = false
attacking = true
wait(.95)
attacking = false
canattack = true
end
end)
script.Parent.Handle.Touched:Connect(function(h)
if h.Parent:findFirstChild('Humanoid') then
if attacking == true then
attacking = false
script.Parent.damage:InvokeServer(h.Parent.Humanoid)
end
end
end)
and the server script
local debris = game.Debris
function damage(plr,h)
h:TakeDamage(math.random(3.75,10))
local sound = Instance.new("Sound",script.Parent.Handle)
sound.SoundId = 'rbxassetid://175024455'
sound:Play()
debris:AddItem(sound,1)
end
The way you loaded the animation is deprecated, you should instead use the Animator to load the animation. Create an Animator and set its parent to the Humanoid.
Though there is another problem, no one can see the animation besides me. I just tested it with my friend and he saw nothing happening. If you know the problem for this reply at any time you want. Thank you!
Then you have to play the animation on the server not on the client, so fire a remote event to the server from the client when the tool or Button is activated. Put the animation in the replicatedstorage so that the server can access the animation.
Client
local RepStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = RepStorage.RemoteEvent -- assign the remote event to a variable
script.Parent.Activated:Connect(function()
if canattack == true then
RemoteEvent:FireServer() -- fire a remote event to the server so that the
-- the animations can be played for everyone
local sound = Instance.new("Sound",script.Parent.Handle)
sound.SoundId = 'rbxassetid://541909814'
sound:Play()
debris:AddItem(sound,1)
canattack = false
attacking = true
wait(.95)
attacking = false
canattack = true
end
Server
local RepStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = RepStorage.RemoteEvent -- assign the remote event to a variable
RemoteEvent.OnServerEvent:Connect(function(plr)
local Animation = game.ReplicatedStorage.Animation -- retrieve your animation from the rep storage and assign it to a variable
local character = plr.Character or plr.CharacterAdded:Wait()
local Animator = character:WaitForChild("Humanoid"):WaitForChild("Animator") -- get the animator
local AnimationTrack = Animator:LoadAnimation(animation)
AnimationTrack:Play() -- play the track on the server
end)
I am such an idiot. I feel like its obvious where the answer is. But anyway i got this error. This is the server script
this is the script:
local RepStorage = game:GetService(“ReplicatedStorage”)
local RemoteEvent = RepStorage.animation
local player = game.Players.LocalPlayer-- assign the remote event to a variable
local char = workspace[player.Name]
script.Parent.Equipped:Connect(function()
RemoteEvent.OnServerEvent:Connect(function(plr)
local hold = game.ReplicatedStorage.holding -- retrieve your animation from the rep storage and assign it to a variable
local character = plr.Character or plr.CharacterAdded:Wait()
local Animator = character:WaitForChild("Humanoid"):WaitForChild("Animator") -- get the animator
local AnimationTrack = Animator:LoadAnimation(hold)
AnimationTrack:Play() -- play the track on the server
end)
local attack = game.ReplicatedStorage.attacking -- retrieve your animation from the rep storage and assign it to a variable
local character = plr.Character or plr.CharacterAdded:Wait()
local Animator = character:WaitForChild("Humanoid"):WaitForChild("Animator") -- get the animator
local AnimationTrack = Animator:LoadAnimation(attack)
AnimationTrack:Play() -- play the track on the server
No, what are you doing. You are supposed to create 2 scripts, a local script and a script, I have told you to put the client code that I gave you to a local script and put the server code into a script.
Parent the local script to the StarterPlayerScripts and put the script in the ServerScriptService