I made a sword, and in the sword it uses ClientCaster . I put a global script inside and then I used a function from ClientCaster called HumanoidCollided which means the sword collided with a humanoid. This works perfectly, it takes damage away and does what it needs to do. Then I made a event and fired it to the client inside humanoidcollided with the parameter of the player and the hit player. The Event fires but inside the client script it errors out “Attempt to index nil with “name”” for the hit humanoid.
Now I am wondering how it’s indexing nil
Output:
LocalScript:36: attempt to index nil with 'Name'
Global Script
ClientCaster.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
if HitHumanoid and HitHumanoid ~= script.Parent.Parent.Humanoid then
if Debounce2[HitHumanoid] then
return
end
local play_er = game.Players:GetPlayerFromCharacter(Tool.Parent)
UntagHumanoid(HitHumanoid)
TagHumanoid(HitHumanoid, play_er,script.Parent.Parent.Name)
local Damage
if combo == 1 then
Damage = SettingsFolder.Slash1Damage.Value
elseif combo == 2 then
Damage = SettingsFolder.Slash2Damage.Value
elseif combo == 3 then
Damage = SettingsFolder.Slash3Damage.Value
elseif combo == 4 then
Damage = SettingsFolder.Slash4Damage.Value
end
Debounce2[HitHumanoid] = true
print("Fired Client")
GlobalEventFolder.Sword.PlayerKilled:FireClient(play_er,HitHumanoid.Parent)
HitHumanoid:TakeDamage(Damage)
if HitHumanoid.Health <= 0 then
if play_er.Health ~= 100 then
play_er.Health = play_er.Health + 25
end
end
SoundsFolder.Hit:Play()
wait(0.7)
Debounce2[HitHumanoid] = false
end
end)
The client you are sending remoteevent parameter is invisible for the client, remove the first parameter “Player” from the LocalScript connection and it should work
ClientCaster.HumanoidCollided:Connect(function(RaycastResult, HitHumanoid)
if HitHumanoid and HitHumanoid ~= script.Parent.Parent.Humanoid then
if Debounce2[HitHumanoid] then
return
end
local play_er = game.Players:GetPlayerFromCharacter(Tool.Parent)
UntagHumanoid(HitHumanoid)
TagHumanoid(HitHumanoid, play_er,script.Parent.Parent.Name)
local Damage
if combo == 1 then
Damage = SettingsFolder.Slash1Damage.Value
elseif combo == 2 then
Damage = SettingsFolder.Slash2Damage.Value
elseif combo == 3 then
Damage = SettingsFolder.Slash3Damage.Value
elseif combo == 4 then
Damage = SettingsFolder.Slash4Damage.Value
end
Debounce2[HitHumanoid] = true
print("Fired Client")
local HitPlayer = game.Players:GetPlayerFromCharacter(HitHumanoid.Parent)
GlobalEventFolder.Sword.PlayerKilled:FireClient(play_er,HitPlayer)
HitHumanoid:TakeDamage(Damage)
if HitHumanoid.Health <= 0 then
if play_er.Health ~= 100 then
play_er.Health = play_er.Health + 25
end
end
SoundsFolder.Hit:Play()
wait(0.7)
Debounce2[HitHumanoid] = false
end
end)
What do you mean emulator? If you mean roblox studio, yes. PlayerKilled is not nil and I think you are right about HitPlayer being nil on the server but I am not sure how I am going to fix that.