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

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

Asked by
RootEntry 111
7 years ago

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

Log in to vote
0
Answered by 7 years ago

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.

Ad

Answer this question