ServerScriptService.Combat.Hit:5: attempt to perform arithmetic (sub) on Instance and number

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)


1 Like

“dummy” that you are referencing in the Server Script is passed as the character object already through the LocalScript. Your line on the server would be:

dummy.Health = dummy.Health - 25

or

dummy.Health -= 25

Instead of referencing dummy.Character.

1 Like

Damn, i didn’t realize i put character there, LOL. Should’ve honestly looked more clearly at the code before posting a thread.

1 Like

For some reason, it’s still erroring.

“Humanoid is not a valid member of Player “Players.RealRaiarGaming100YT””

This error pops up even tho it’s not supposed to damage my player, and it’s supposed to damage the dummy.

1 Like

That’ll be this line of the LocalScript:
image

RemoteEvent:FireServer() already passes the player parameter by default, so you don’t need to include it in your LocalScript. On the Server, your code will remain the same (including the fix above).

Your new line will be:

game.ReplicatedStorage.Hit:FireServer(dummy)

Useful resources:
RemoteEvent | Roblox Creator Documentation