Why isn't this working?

I’m making a script for an axe that does damage when it’s hit. TakeDamage is going to be done on the server, obviously, so i’m using a RemoteEvent. For some reason, doing

-- local script inside tool, this is the part that fires the remoteevent
script.Parent.Handle.Touched:Connect(function(hit)
	if hit and canSwing == false then
		local hum = hit.Parent:FindFirstChild("Humanoid")
		if hum and hum ~= plrHum then
			local selected = hitsounds[math.random(1, #hitsounds)]
			selected:Play()
			game.ReplicatedStorage.Damage:FireServer(hum, 15)
		end
	end
end)

and

local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("Damage")

Event.OnServerEvent:Connect(function(hum, amount)
	hum:TakeDamage(amount)
end)

gives me this in output when i swing at a dummy.

TakeDamage is not a valid member of Player "Players.milkmanthememer" -- milkmanthememer is my main account im creating this game on
1 Like

the first argument of OnServerEvent is always the player that fired the event.

local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("Damage")

Event.OnServerEvent:Connect(function(player, hum, amount)
	hum:TakeDamage(amount)
end)
2 Likes

theres a player argument on .OnServerEvent, you can prevent it by doing _

Event.OnServerEvent:Connect(function(_,hum, amount)
	hum:TakeDamage(amount)
end)

I see, I thought this was for FireClient only, but i was wrong.

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