Trouble with BindableEvents

I have make a server script for a very simple knife but instead of dealing the damage on the knife’s script I am trying to pass the information over to another server script via a BindableEvent. Everything works well until the information got passed over to the other script, I have tried to fix it but I don’t know how.
Knife’s server script:

local DebounceTable = {}
local RS = game:GetService("ReplicatedStorage")
local BE = RS.ReviveBE

script.Parent:WaitForChild("HitBox").Touched:Connect(function(hitPart)
	if hitPart.Parent and hitPart.Parent:WaitForChild("Humanoid") then
		local playerCharacter = hitPart.Parent
		local player = game.Players:GetPlayerFromCharacter(playerCharacter)
		if player then
			if DebounceTable[player] == true then return end
			DebounceTable[player] = true
			BE:Fire(player)
			print("Successfully fired the BindableEvent")
			wait(2)
			DebounceTable[player] = nil
	else
		print("Not a player")
		end
	end
end)

ServerScript in ServerScriptService:

local RS = game:GetService("ReplicatedStorage")
local BE = RS.ReviveBE

BE.Event:Connect(function(playerThatWasHit)
	wait(0.5)
	print("BindableEvent has recieved information")
	print("Player was hit:", playerThatWasHit)
	local Humanoid = playerThatWasHit.Character and playerThatWasHit.Character:FindFirstChild("Humanoid")
	if Humanoid then
		print("Got past the humanoid stage")
		playerThatWasHit.Parent.Humanoid:TakeDamage(30)
		print("Player is taking damage")
	end
end)

The second script is the one I am having trouble with. I have included prints to see where the code stops. I get an error where the “Local Humanoid” is located, saying “Humanoid is not a valid member of Players ‘Players’”. What I am trying to achieve is that once the knifes hitbox touches another player it fires the BindableEvent, then the BindableEvent needs to know what player got hit and apply the damage to them.

You are getting the Humanoid from the Parent of the Player, which is the Players Container? The Container that holds all the Player Instances?

1 Like

Should there be no Parent after “playerThatWasHit”?

No?

The Player Instance has to be Parented somewhere, which is where Players comes in, where they were always at, the Parent of Players is game, and the Parent of game is nil (no value).

You are checking if the Humanoid Exists, but then you checked if the Parent of the Player (Players) had the Humanoid, which It doesnt, so this is all you need to do:

if Humanoid then
    Humanoid:TakeDamage(30)
end

Which the Humanoid was already Found, you were just checking in a Diffrent place.

1 Like

Ok I replaced parent with character and it worked. I also tried your approach and it worked too.

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