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

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

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

2 comments

0

is this a local script? if so, you can just use the Clone() function and game.Players.LocalPlayer

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.

1 answer

✓ Accepted answer

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!

2 comments

0

Thanks a ton

0

No problem!

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