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

Gui keeps copying?

function onTouched(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local gui = game.ServerStorage.PerkShop
		local guiClone = gui:clone()
		if not player.PlayerGui:FindFirstChild(guiClone)then
		guiClone.Parent = player.PlayerGui
		end
	end
end

script.Parent.Touched:connect(onTouched)

Honestly lost now, thought I did this all perfectly. All the help is appreciated!

1 answer

✓ Accepted answer

The line:-

if not player.PlayerGui:FindFirstChild(guiClone)then

Try's to use the object guiClone and not the name of the gui

Simply add Name:-

function onTouched(hit)
    if hit.Parent:findFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local gui = game.ServerStorage.PerkShop
        local guiClone = gui:clone()
        if not player.PlayerGui:FindFirstChild(guiClone.Name)then
        guiClone.Parent = player.PlayerGui
        end
    end
end

script.Parent.Touched:connect(onTouched)

This is because the method FindFirstChild will not convert the object into a string so the result will be nil allowing for duplicates.

1 comment

0

I was so close XD thank you for the help!

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