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

How do I get this script to clone a GUI and put it in the PlayerGUI?

This question exists solely in my lack of lua knowledge eue.

I'm trying to make a shopkeeper and when you walk near the NPC, it displays a GUI on your screen, simple enough.


function Enter()
	script.NPCDialauge:Clone().Parent = v.Players.PlayerGUI
	script.NPCDialauge:TweenPosition(UDim2.new(0, 500,0, 250), "In", "Sine", 2, true)
end


while true do
	for i, v in pairs (game.Players:GetChildren()) do
		if (v.Character.Torso.Position - script.Parent.Position).magnitude <= 10 then
			Enter()
		end
	end
	wait()
end

How do I get this to clone the GUI and put it in the character who nears the NPC? You can see the obvious error DX I just don't know how to fix it.

1 comment

0

It's PlayerGui not PlayerGUI. Lua is case sensitive.

1 answer

✓ Accepted answer

v on line 02 is undefined, to fix, place a Parameter in Enter function.

function Enter(v)
    script.NPCDialauge:Clone().Parent = v.PlayerGui
    script.NPCDialauge:TweenPosition(UDim2.new(0, 500,0, 250), "In", "Sine", 2, true)
end


while true do
    for i, v in pairs (game.Players:GetChildren()) do
        if (v.Character.Torso.Position - script.Parent.Position).magnitude <= 10 then
            Enter(v)
        end
    end
    wait()
end

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