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

What's wrong with this script?

When the player sits in the seat, the GUI should clone. When the player jumps out, the GUI should destroy itself. This just isn't happening!

Please help me!

gui = script.Parent.Controls
guiClone = nil

script.Parent.ChildAdded:connect(function(SeatWeld)
	char = SeatWeld.Part1.Parent
	player = game.Players:GetPlayerFromCharacter(char)
	guiClone = gui:Clone()
	guiClone.Parent = player.PlayerGui
end)

script.Parent.ChildRemoved:connect(function(removeWeld)
	if guiClone then
		guiClone:Destroy()
	end
end)

1 answer

gui = script.Parent.Controls
guiClone = nil

script.Parent.ChildAdded:connect(function(SeatWeld)
    char = SeatWeld.Part1.Parent
    player = game.Players:GetPlayerFromCharacter(char)
    guiClone = gui:Clone()
    guiClone.Parent = player.PlayerGui
end)

script.Parent.ChildRemoved:connect(function(removeWeld)
    if guiClone then
        gui:Destroy() --- you were destroying the guiClone, not the GUI itself 
    end
end)

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