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

how can I clone a GUI to the PlayerGui with no parameter?

Asked by
Z0ggg 20
5 years ago

I understand that ClickDetector functions have built-in parameters can easily pave a way to the PlayerGui, but I can't get one for events like MouseEnter. Anyway I can access the PlayerGui so the UI won't appear for all the players (I'm fairly sure filtering-enabled limit that but still) with a GUI/mouse relationship?

example:

--Script under TextButton under ScreenGui

script.Parent.MouseEnter:Connect(function(plr)  --missing value for plr parameter
    print("Insert whatever code in here, cloning other UI, making its parent the PlayerGui.")
end
0
is this a local script? if so, you can just use the Clone() function and game.Players.LocalPlayer theking48989987 2147 — 5y
0
Yes it is a local script. I've tried using LocalPlayer earlier, but I have an idea with it. I'll get back to you. Z0ggg 20 — 5y

1 answer

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

First of all, you need to use a LocalScript when handling GUIS in the Player. So, create a LocalScript inside of your TextButton. First we need to get the LocalPlayer, which is simple:

local Player = game:GetService("Players").LocalPlayer

Now, we need to listen to the MouseEnter event and connect it

script.Parent.MouseEnter:Connect(function() -- there is no need for any parameters

Now, where is the GUI we want to clone? Let's say it's in game.ReplicatedStorage, and it's called "Alpha". To continue, we would do:

script.Parent.MouseEnter:Connect(function()
    game:GetService("ReplicatedStorage").Alpha:Clone().Parent = Player.PlayerGui
    -- replace with your actual GUI
end)

Final Script:

local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseEnter:Connect(function()
    game:GetService("ReplicatedStorage").Alpha:Clone().Parent = Player.PlayerGui
    -- replace with your actual GUI
end)

It's as simple as that! If you want to make sure that the Player doesn't hover multiple times and keep getting the GUI cloned, you can create a Debounce.

local Passed = false 
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseEnter:Connect(function()
    if Passed == false then 
        game:GetService("ReplicatedStorage").Alpha:Clone().Parent = Player.PlayerGui
        -- replace with your actual GUI
        Passed = true 
        wait(100) -- wait (x) amount of seconds
        Passed = false -- allows player to hover and get the GUI again
    end
end)

Again, we are using a LocalScript here!

Please accept my answer if it helped you out, and feel free to comment if you have any questions or if you're confused on anything. Good luck!

0
Thanks a ton Z0ggg 20 — 5y
0
No problem! DaCrazyDev 444 — 5y
Ad

Answer this question