Server sided damage script not working

I’m making a local script that creates a hitbox and a server script that detects when that hitbox hits a humanoid, then damages them. For some reason, the server side script is completely unresponsive. I’m not sure why as there aren’t any errors. I figure the reason why it doesn’t work is because I’m not actually detecting for a hit on a humanoid other than the character’s humanoid, but again, I’m not sure how to fix that.

Here’s a snippet from the local script which connects to the server script -

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == keybind then
		anim:Play()
		newHitbox1:SetPoints(rightarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		event:FireServer()
		newHitbox1:HitStart(1)
	end
end)

This is the server script:

local player = game:GetService("Players")
local replicatedstorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(replicatedstorage.RaycastHitboxV4)

game.ReplicatedStorage.instadeath.OnServerEvent:Connect(function(player, hit)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local leftarm = player.Character:WaitForChild("Left Arm")
	local newHitbox1 = RaycastHitbox.new(leftarm)

	newHitbox1.OnHit:Connect(function(hit, humanoid)
		newHitbox1:RemovePoints(leftarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		print("hit1")
		humanoid:TakeDamage(25)
	end)
end)

Please let me know if you know how to fix this!

The problem is when your firing the remoteevent on the localscript its not sending the variable hit as you can see here on line 6

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == keybind then
		anim:Play()
		newHitbox1:SetPoints(rightarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		event:FireServer() -- here
		newHitbox1:HitStart(1)
	end
end)

Putting the variable hit in the argument for FireServer() didn’t work, it’s giving me an unknown global error - can you elaborate on this if I’m missing something?

What is the hit variable meant to be the reason why its giving you an unknown global error is because its not a value

wait I have an idea and if this doesnt work then I have no idea

Server Script

local player = game:GetService("Players")
local replicatedstorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(replicatedstorage.RaycastHitboxV4)

game.ReplicatedStorage.instadeath.OnServerEvent:Connect(function(player)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local leftarm = player.Character:WaitForChild("Left Arm")
	local newHitbox1 = RaycastHitbox.new(leftarm)

	newHitbox1.OnHit:Connect(function(hit, humanoid)
		newHitbox1:RemovePoints(leftarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		print("hit1")
		humanoid:TakeDamage(25)
	end)
end)

Local Script

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == keybind then
		anim:Play()
		newHitbox1:SetPoints(rightarm, {Vector3.new(0.5, 1, -0.5), Vector3.new(-0.5, 1, 0.5), Vector3.new(0.5, 0, 0.5), Vector3.new(-0.5, 0, -0.5)})
		event:FireServer()
		newHitbox1:HitStart(1)
	end
end)

This isn’t how I do hitboxes, so I’m likely not understanding what I need to.
But

doesn’t this mean the hitbox doesn’t exist on the server’s end, and therefore can’t detect anything?

1 Like

Yea, you’re probably right. Now that I look at both scripts there’s nothing that lets the server know that the client’s hitboxes exist. I’ve had this script work when I defined the hitboxes on the server but there’s really bad delay - better if it’s defined on the client.

Do you have any idea how I could still have hitboxes on the client but have functionality on the server?

upon playing a game you cannot see what is inside server script service or server storage in the explorer, but they will still function!

Yes, this is true and the server script still functions. However, like @Lleventyate and I just said this part is the problem -

newHitbox1.OnHit:Connect(function(hit, humanoid)

Can’t detect what’s not on the server.

The way I do hitboxes is create the hitbox on the client and let the client handle detecting humanoidrootparts.
Send a table of humanoidrootparts to the server, and then the server checks whether each part is within reasonable range of the player creating the hitbox.

3 Likes