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

I am trying to make a house script but this error will show up, how do I fix it?

Here is the script but the error says: 'Workspace.House1.Trigger.Script:6: attempt to index upvalue 'player' (a nil value)'

local player = game.Players.LocalPlayer
enabled = true

workspace:FindFirstChild("House1"):FindFirstChild("Trigger").Touched:connect(function(hit)
	if (enabled == true) then
		workspace:FindFirstChild("House1"):FindFirstChild("userId").Value = player.UserId
	end
end)

1 answer

✓ Accepted answer

Alright so there's a few things you should be doing differently. You can adjust this script, but it is a normal script that goes under workspace right now:


workspace:FindFirstChild("House1"):FindFirstChild("Trigger").Touched:connect(function(hit)
    local Player = game.Players:FindFirstChild(hit.Parent.Name)
    if Player ~= nil then
        workspace:FindFirstChild("House1"):FindFirstChild("userId").Value = Player.UserId
    end
end)

You shouldn't be using a local script to adjust server items, which won't work if you use Fe btw. If you absolutely have to make it client sided for a odd circumstance, then use a remote function and call it from the client.

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