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

Why can I not get the player that touches my part?

script.Parent.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid") then
	local player = workspace[hit.Parent.Name]	
	local plr = game.Players:GetPlayerFromCharacter(player)
		
	plr.owned.nofood.Value = false
		
	end
end)

21:48:04.055 - Workspace.Map.weGYM.Foodallowed.Script:7: attempt to index nil with 'owned' 21:48:04.055 - Stack Begin 21:48:04.055 - Script 'Workspace.Map.weGYM.Foodallowed.Script', Line 7 21:48:04.055 - Stack End

-- This is in a server script inside the part.

3 comments

0

instead of doing workspace[hit.Parent.Name] just do hit.Parent

0

or just delete the whole local player = ... line and just do local player = game.Players:GetPlayerFromCharacter(hit.Parent)

0

Thanks.

1 answer

Subsz was correct, "instead of doing workspace[hit.Parent.Name] just do hit.Parent"

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