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

01script.Parent.Main.Touched:connect(function(hit)
02                if hit.Parent.Name ~= player.Name then
03                    if hit.Parent.Humanoid then
04                        if CanDamage.Value == true then
05                        script.Parent.DamageEvent:FireServer(hit.Parent.Name)
06                        CanDamage.Value = false
07 
08                    end
09                    end
10                    end
11            end)

SERVER SCRIPT

1DamageEvent.OnServerEvent:connect(function(playerhit)
2print(playerhit)
3workspace:FindFirstChild(playerhit).Humanoid:TakeDamage(30)
4 
5end)

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.

1Envoked
202:55:47.252 - Players.Envoked.Backpack.Test Sword.Yeah:36: attempt to index a nil value
302:55:47.252 - Stack Begin
402:55:47.253 - Script 'Players.Envoked.Backpack.Test Sword.Yeah', Line 36
502: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:

1if 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

1hit.Parent ~= player.Character

then replace line 3 with

1if hit.Parent:FindFirstChild("Humanoid")

then replace line 5 with

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

then replace line 1 of the server script with

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

then replace line 2 of the server script with

1print(hit.Parent.Name)

then replace line 3 of the server script with

1hit.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