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

Is it possible to move A GUI from lighting to PlayerGUI?How?

I know I ask a lot of questions but it is because Roblox studio is weird. Something that should be extremely simple, that even a baby could learn to do that in a second, is Extremely complicated in some cases. Right now, I want to move a simple ScreenGUI that I placed in lighting so that you cannot see it to the playergui section inside of the local player.

My raw script:

local debounce = false local touching = false local shop = game.Lighting.PremiumShop local shopTemp = shop:Clone() --Holds a temporary version of shop

script.Parent.Touched:Connect(function(part) --Detects when the player is on the brick so    -- that it can move the GUI

-- I have to learn how to do multi line annotations local hum = part.Parent:FindFirstChild"Humanoid"

    if hum then
        if not debounce then
            debounce = true
            touching = true
 
            while touching do
				shopTemp.parent = game.Players.LocalPlayer.PlayerGui -- finally moves the GUI to player GUI
            end
 
        wait(.5)
        debounce = false
        end
    end
end)
 
script.Parent.TouchEnded:Connect(function(part)
    touching = false
	shopTemp:Destroy() -- Destroy's the copy of GUI in the player, to because non-visible again
end)

Why is such a simple script so complicated to do.

Thank you Nachsor

1 comment

0

.Parent

1 answer

✓ Accepted answer

Hello, nachsor!

Your script causes LAG, the while loop isn't necessary, and your script can be LOTS smaller(And be a normal script too)

And please, don't use Lighting to store things, use Server Storage

Modified script:

script.Parent.Touched:Connect(function(plr)
    if plr.Parent:FindFirstChild("Humanoid") then
        if not game.Players:GetPlayerFromCharacter(plr.Parent).PlayerGui:FindFirstChild(game.Lighting.PremiumShop.Name) then -- Prevents player from having more than 1 gui
            local Shop = game.Lighting.PremiumShop:Clone()
            Shop.Parent = game.Players:GetPlayerFromCharacter(plr.Parent).PlayerGui
        end
    end
end)

script.Parent.TouchEnded:Connect(function(plr)
    if plr.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(plr.Parent).PlayerGui:FindFirstChild(game.Lighting.PremiumShop.Name) then -- Finds the gui on player
        game.Players:GetPlayerFromCharacter(plr.Parent).PlayerGui:FindFirstChild(game.Lighting.PremiumShop.Name):Destroy()
    end
end)

Hope this helps!

Good Luck with your games

3 comments

0

OMG Thank you so much, it worked. I can finally have my shop working. Thank you too much.

0

also, what is wrong with putting things in lighting? its the least used space so I'm sure I can use it.

0

You can, but roblox created Server Storage to store things

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