Hey! I’m trying to script a script where if you left click, it’ll play a punch animation, and if it hits a player, it’ll take damage. The problem is that there’s this annoying error that pops up for the server script. I’ve looked around devforum for posts that can help me, but no one works. Can you help me find out what i did wrong?
LOCAL SCRIPT:
local deb = false
local debdamage = false
local punching = false
local PowerUps = game.ReplicatedStorage.Characters.Flash.PowerUps
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local cooldown = 3
local mouse = plr:GetMouse()
UIS.InputBegan:Connect(function(input)
mouse.Button1Up:Connect(function(click)
plr.Character:WaitForChild("RightHand").Touched:Connect(function(p)
if punching then
if not debdamage then
debdamage = true
local dummy = p.Parent
if dummy then
if dummy.Humanoid.Health > 1 then
game.ReplicatedStorage.Hit:FireServer(plr, dummy)
end
end
end
end
end)
if not deb then
punching = true
deb = true
print("Main Stage")
local animation = Instance.new("Animation", plr)
local anim = game.Workspace:WaitForChild("Animations").Punches:GetChildren()
local randomAnim = anim[math.random(1, #anim)]
animation.AnimationId = randomAnim.AnimationId
local hum = plr.Character:WaitForChild("Humanoid")
local loaded = hum:LoadAnimation(animation)
loaded:Play()
wait(cooldown)
deb = false
punching = false
debdamage = false
end
end)
end)
SERVER SCRIPT:
game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(plr, dummy)
dummy.Character.Health = dummy.Character.Health - 25
end)