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
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