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

I tried to copy a gui from a part when someone touched it, but it says a error?

Here is the code I have inside of the part.

local player = game.Players.LocalPlayer
local storage = game:GetService("ServerStorage")
local gui = storage:WaitForChild("HomeGui")

workspace:FindFirstChild("House1"):FindFirstChild("Doors"):FindFirstChild("Door1").Touched:connect(function(hit)
	if hit.Parent.Humanoid then
		gui:FindFirstChild("House1"):Clone().Parent = player:WaitForChild("PlayerGui")
		workspace:FindFirstChild("House1"):FindFirstChild("Doors"):FindFirstChild("Door1"):FindFirstChild("Script").Disabled = true
	end
end)

And the error is: 17:47:59.182 - Workspace.House1.Doors.Door1.Script:7: attempt to index upvalue 'player' (a nil value)

1 comment

0

So I see it is "player = game.Players.LocalPlayer" If it's a ServerScript, that won't work. Also, if it is a LocalScript, you might need to edit it.

1 answer

✓ Accepted answer

Try this:

local storage = game:GetService("ServerStorage")
local gui = storage:WaitForChild("HomeGui")

workspace:FindFirstChild("House1"):FindFirstChild("Doors"):FindFirstChild("Door1").Touched:connect(function(hit)
    if hit.Parent.Humanoid then
	local player= game.Players:GetPlayerFromCharacter(hit.Parent)
        gui:FindFirstChild("House1"):Clone().Parent = player:WaitForChild("PlayerGui")
        workspace:FindFirstChild("House1"):FindFirstChild("Doors"):FindFirstChild("Door1"):FindFirstChild("Script").Disabled = true
    end
end)

(local player only works with LocalScripts, this script will detect the player by it's character.)

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