Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the output saying the local players name, instead of the "hit"' name?

Asked by
Envoked -11
6 years ago

So i'm trying to detect when a part gets touched, and if hit has met a certain qouta, inflict damage. heres the script.

LOCAL SCRIPT

script.Parent.Main.Touched:connect(function(hit)
                if hit.Parent.Name ~= player.Name then
                    if hit.Parent.Humanoid then
                        if CanDamage.Value == true then
                        script.Parent.DamageEvent:FireServer(hit.Parent.Name)
                        CanDamage.Value = false

                    end
                    end
                    end
            end)

SERVER SCRIPT

DamageEvent.OnServerEvent:connect(function(playerhit)
print(playerhit)
workspace:FindFirstChild(playerhit).Humanoid:TakeDamage(30)

end)

so when i press play and hit something, (the output should say four, since im hitting a dummy named four), the output prints out the local players name. and saying its a nil value- even though ive checked over everything and it should be working.

Envoked
02:55:47.252 - Players.Envoked.Backpack.Test Sword.Yeah:36: attempt to index a nil value
02:55:47.252 - Stack Begin
02:55:47.253 - Script 'Players.Envoked.Backpack.Test Sword.Yeah', Line 36
02:55:47.253 - Stack End
0
LocalScripts can’t run under the Workspace... User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Try using:

if player.Name == game.Players.LocalPlayer.Name then else
Ad
Log in to vote
0
Answered by
Launderer 343 Moderation Voter
6 years ago

Replace line 2 in the local script with

hit.Parent ~= player.Character

then replace line 3 with

if hit.Parent:FindFirstChild("Humanoid")

then replace line 5 with

script.Parent.DamageEvent:FireServer(hit.Parent)

then replace line 1 of the server script with

DamageEvent.OnServerEvent:Connect(function(hit.Parent)

then replace line 2 of the server script with

print(hit.Parent.Name)

then replace line 3 of the server script with

hit.Parent.Humanoid:TakeDamage(30)
0
It still gives me the 13:56:54.234 - [Players.Envoked.Backpack.Test Sword.Yeah:36: attempt to index a nil value] error. Thanks for trying though :D Envoked -11 — 6y

Answer this question