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

GUI Cloning But Locking its Local Parent?

Asked by 7 years ago

All I want is when you click on a part you see the GUI and you can use it. The first time you click it works but perfectly fine. The second time it reads this:

08:27:11.682 - The Parent property of CardGiverGui is locked, current parent: NULL, new parent PlayerGui 08:27:11.683 - Stack Begin 08:27:11.683 - Script 'Workspace.Part.Script', Line 5 08:27:11.684 - Stack End

My Script:

GUI = script.Parent.CardGiverGui

function onClicked()
    GUI:Clone()
    GUI.Parent = game.Players.LocalPlayer.PlayerGui
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You have to clone it and then put that clone inside the player. You have cloned it but then put the original into the player. Let's fix it.

local Gui = script.Parent.CardGiverGui

function onClicked()
    local GUI = Gui:Clone()
    GUI.Parent = game.Players.LocalPlayer.PlayerGui
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Now, if you want it so they only get it if they don't have the Gui already then use this code; (It will make it so they don't have loads of Gui's)

local Gui = script.Parent.CardGiverGui
local plr = game.Players.LocalPlayer

function onClicked()
    local GUI = Gui:Clone()
    if plr.PlayerGui:FindFirstChild("GUI NAME") then
        --Do nothing
    else
       GUI.Parent = plr.PlayerGui
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
Ad

Answer this question