Issue with a script when trying to make punch system has damage base on player stats?

Hello, I’m OriginalDevelops, totally, I’m just a new scripter, I’m trying to make a punch system has damage base on player stats value! This is a script so it can happend on server, but it didnt work :disappointed_relieved:. I’ve trying to make on a local script, it work correctly but the problem is it only happend in the client when kill a people! ( I mean the player that kill a people only happend on a client! And the people got kill still alive and not respawning, on their client still alive!) .This is my code :

Left PunchDamage

local debounce = false

script.Parent.Equipped:Connect(function()
	
	local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)
	local char = player.Character or player.CharacterAdded:Wait()
	
	local leftarm = char:WaitForChild("LeftHand")
	
	leftarm.Touched:Connect(function(hit)
		if not debounce then
			debounce = true
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= char.Name then
					hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - (player.Stats.Strength.Value + 1)
					print(hit)
					wait(0.5)
					debounce = false
			end
		end
	end)
end)

Right Punch Damage :

local debounce = false

script.Parent.Equipped:Connect(function()
	
	local player = script:FindFirstAncestorWhichIsA"Player" or game:GetService"Players":GetPlayerFromCharacter(script.Parent.Parent)
	local char = player.Character or player.CharacterAdded:Wait()
	
	local rightarm = char:WaitForChild("RightHand")
	
	rightarm.Touched:Connect(function(hit)
		if not debounce then
			debounce = true
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= char.Name then
					hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - (player.Stats.Strength.Value + 1)
					print(hit)
					wait(0.5)
					debounce = false
			end
		end
	end)
end)

I wish someone can fix this for me so I can complete a part of my game!

1 Like

Try replacing hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - (player.Stats.Strength.Value + 1) with hit.Parent.Humanoid:TakeDamage(player.Stats.Strength.Value + 1)

IS this the local script? it’s kinda odd looking at this script, Actually nevermind. yeah it’s on client

So uhhh, When you make a weapon you need to replicate stuff from local script to Server script

1 Like

Btw just realized you’re putting the debounce in the wrong place.

This is a script, I tried on local script, it worked correctly but the script didn’t… I want it work on server!

Try to learn how to use RemoteEvent or RemoteFunction (same as remoteEvent but you can return back the value)

As you can see, this script works on client but FilterEnabled exist to Anti easy exploit

so you gotta use remote event to replicate the info to server side and make a server script handle those info

1 Like

What place should I put the debounce?

Put it right after the if statement that perform the damage.

But how can I send an info of the hit to the server? Can you give me an example?

Uhhhh, Yeah
for example,

You have a tool, and you may wanna insert a RemoteEvent into the Tool
and then get a server script to handle the Remote Event
by for example
Tool:WaitForChild(“RemoteEvent”).OnServerEvent:Connect(function(Player,Info1,Info2)
end)
every remoteEvent give out player info first so remember that

It didn’t work althrough… :disappointed_relieved:

Humm, can you explain more about the info1 and info2? Maybe you can message me about…

now you wanna replicate your info from client by Tool:WaitForChild(“RemoteEvent”):FireServer(informations)
info1,info2 came from the Client side, You can send as many info as you want

Local Script –

Tool.RemoteEvent:FireServer(“Garry”,“Team”)

Script –

Tool.RemoteEvent.OnServerEvent:Connect(function(player,info1,info2)
print(info1,info2)
end)

try to experiment with this and learn to adapt it to your script

Oh, so that mean when I fire a Remote in a local script, then I put hit value in then in the fireserver line, I put script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr, hit)) so that will get the hit object right?

Correct, But I recommend to send info by Humanoid,Damage instead

Okay, I will try! :grinning: :+1:

Should be something like this
–Local Script–
Tool.RemoteEvent:FireServer(Humanoid,Damage)

–Server Script–
Tool.RemoteEvent.OnServerEvent:Connect(function(player,Humanoid,Damage)
if Humanoid then
Humanoid.Health = Humanoid.Health - Damage
end
end)

Thanks you it worked now :grinning: