when the player activates the tool it fires a remote event that leads into a server script where then once the server script receives the event it choose a random animation out of three animations and plays it.
but when i test it, it doesn’t seem to be working.
there is no errors.
local Tool = script.Parent
local Handle = Tool.Handle
local Anims = Tool.Anims
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(Tool.Hitbox)
local de = false
local canHit = false
config = {
Damage = 15,
AttackTime = .25,
Cooldown = .25
}
Hitbox.OnHit:Connect(function(hit, humanoid)
if canHit == false then return end
canHit = false
if humanoid.Parent ~= script.Parent.Parent then
humanoid:TakeDamage(config.Damage)
local character = humanoid.Parent
local Knockback = Instance.new("BodyVelocity")
Knockback.P = math.huge
Knockback.Parent = character:FindFirstChild("HumanoidRootPart")
Knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
Knockback.Velocity = character:FindFirstChild("HumanoidRootPart").CFrame.lookVector * -7
game:GetService("Debris"):AddItem(Knockback, .3)
task.wait(.35)
end
canHit = true
end)
script.Parent.Hit.OnServerEvent:Connect(function(Player)
if de == false then
de = true
local Humanoid = Player.Character.Humanoid
local AnimationsList = Anims:GetChildren()
local Selected = Humanoid:LoadAnimation(AnimationsList[math.random(1, #AnimationsList)])
Selected:Play()
Hitbox:HitStart()
wait(config.AttackTime)
canHit = true
wait(config.Cooldown)
Hitbox:HitStop()
canHit = false
de = false
end
end)
why, that line is in a server script. theres two scripts local and server scripts in the tool. the local script just checks when the tool is activated and then fires an event.
Instead of using wait() to control timing, consider using RunService for more precise timing and better responsiveness.
LoadAnimation Error Handling:
Ensure that the LoadAnimation call is successful. If the selected animation fails to load, it could be a source of the problem.
Check the RemoteEvent:
Confirm that the RemoteEvent (script.Parent.Hit.OnServerEvent) is set up correctly on the client side and is being fired appropriately.
And so my rescript version probably looks like this?
local Tool = script.Parent
local Anims = Tool.Anims
local RunService = game:GetService("RunService")
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(Tool.Hitbox)
local de = false
local canHit = false
local config = {
Damage = 15,
AttackTime = 0.25,
Cooldown = 0.25
}
Hitbox.OnHit:Connect(function(hit, humanoid)
if canHit == false then return end
canHit = false
if humanoid.Parent ~= Tool.Parent then
humanoid:TakeDamage(config.Damage)
local character = humanoid.Parent
local Knockback = Instance.new("BodyVelocity")
Knockback.P = math.huge
Knockback.Parent = character:FindFirstChild("HumanoidRootPart")
Knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
Knockback.Velocity = character:FindFirstChild("HumanoidRootPart").CFrame.lookVector * -7
game:GetService("Debris"):AddItem(Knockback, 0.3)
wait(0.35)
end
canHit = true
end)
script.Parent.Hit.OnServerEvent:Connect(function(Player)
if de == false then
de = true
local Humanoid = Player.Character:FindFirstChildOfClass("Humanoid")
if Humanoid then
local AnimationsList = Anims:GetChildren()
if #AnimationsList > 0 then
local Selected = Humanoid:LoadAnimation(AnimationsList[math.random(1, #AnimationsList)])
if Selected then
Selected:Play()
Hitbox:HitStart()
wait(config.AttackTime)
canHit = true
wait(config.Cooldown)
Hitbox:HitStop()
canHit = false
else
warn("Failed to load animation.")
end
else
warn("No animations found.")
end
else
warn("Humanoid not found.")
end
de = false
end
end)
i tried that and nothing changed. But i think i found the problem. I changed the animation to mvoe the leg instead and it worked. but when the animation is to move the arm holding the tool it doesn’t play.
i dont know how this would be though since like the tool isnt anchored or anything so.