✓ 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()
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
end)
Final Script:
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseEnter:Connect(function()
game:GetService("ReplicatedStorage").Alpha:Clone().Parent = Player.PlayerGui
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
Passed = true
wait(100)
Passed = false
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
is this a local script? if so, you can just use the Clone() function and game.Players.LocalPlayer
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.