Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

0

LocalScripts can’t run under the Workspace...

2 answers

Try using:

if player.Name == game.Players.LocalPlayer.Name then else

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)

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.