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

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

Asked by 3 years ago
Edited 3 years ago
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.

0
instead of doing workspace[hit.Parent.Name] just do hit.Parent Subsz 366 — 3y
0
or just delete the whole local player = ... line and just do local player = game.Players:GetPlayerFromCharacter(hit.Parent) blazar04 281 — 3y
0
Thanks. firespear500 12 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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

Ad

Answer this question