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

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

Asked by
nachsor 36
6 years ago

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

0
.Parent LuaDLL 253 — 6y

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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

0
OMG Thank you so much, it worked. I can finally have my shop working. Thank you too much. nachsor 36 — 6y
0
also, what is wrong with putting things in lighting? its the least used space so I'm sure I can use it. nachsor 36 — 6y
0
You can, but roblox created Server Storage to store things Leamir 3138 — 6y
Ad

Answer this question