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

Gui keeps copying?

Asked by 8 years ago
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

Log in to vote
0
Answered by 8 years ago

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.

0
I was so close XD thank you for the help! Squidier 40 — 8y
Ad

Answer this question