[SOLVED] Weapon Damage Not Occurring in Multiplayer Servers

I’ve been trying to make a weapon from scratch, but I’m not the best scripter, just a beginner. I tried to script up a weapon, but the damage only works in single-player studio runs (testing on NPC dummies), not in-game or if I try to run local server test in studio.

Here is the full script:
(Script>Tool>Handle)

local debounce = false

local function onTouched(hit)
	if debounce == false then
		debounce = true
		hit.Parent.Humanoid:TakeDamage(24)
		wait(3)
		debounce = false
	end
end


script.Parent.Touched:Connect(onTouched)

EDIT:

Alright, I tried using RemoteEvent but I’m not sure how to do this. What I have so far is a fire script for a remote event.

game.ReplicatedStorage.Damage:FireServer(Someone) 
-- "Someone" is script.Parent.Touched

How do I make a Remote Event that does damage to “Someone”?

Is this in a local script? If any part of this system is in a local script, it won’t get replicated to the server (except in special circumstances). If it doesn’t get replicated to the server, other players won’t see it. The reason it may appear to work in studio is because the information your seeing in the explorer and properties windows are representative of what your client sees. The server may not necessarily be the same.

1 Like

You should instead use a remoteEvent (i think it was that one) to send information to the server, then have a server script deal the damage instead (send the amount of dmg, and who got hit)

1 Like

No, its all in a script. I’ll try to figure out how to send damage to the server

Alright, ill work on figuring that out once i get on my PC. Thanks for the help!

So basically, what I have so far is a fire script for a remote event.

game.ReplicatedStorage.Damage:FireServer(Someone) 
-- "Someone" is script.Parent.Touched

How do I make a Remote Event that does damage to “Someone”?

add a second dmg value, then, in a server script, receive the FireServer (I forgot what exactly your supposed to use), and put the damaging thing there (the humanoid:TakeDamage part)

and remember the first value is the sender, so it should be like (plr, someone, dmg)

You shouldnt need a remote event to do all this stuff… ill give you some code, and tell me if it works…

local debounce = false

local function onTouched(hit)
	if hit.Parent ~= nil then
		local human = hit.Parent:FindFirstChildOfClass("Humanoid")
		if human then
			if debounce == false then
				debounce = true
				human.Health -= 24
				wait(3)
				debounce = false
			end
		end
	end
end


script.Parent.Touched:Connect(onTouched)
remoteEvent.OnServerEvent:Connect(function(player) --player is character thats receiving the remote event
	local character = player.Character
	local human = character:FindFirstChildOfClass("Humanoid")
	
	human.Health -= 24
end)

well I totally forgot you could just use a server script

but wouldn’t that result in a whole lot of serverscripts if everyone in the server had a sword?

Yes, it works! Tysm!
I genuinely appreciate your help, I picked a few things up from your script. Thank you!!

Yes, it would result in a lot of server scripts, but it is more practical as it is open to more customization, and it runs fine.

If it works, you should select my reply as solution, or add “[SOLVED]” in the title. This is to prevent players from clicking on a topic that is solved.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.