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

How do I make a gui show up for only the player that interacts with the click detector?

How the script works/issue: When a player clicks on a part via a click detector a gui appears but it appears for all of the players which is not ideal. My script is a normal script but I don't know if I should use a local script or if a local script will even work.

Any help?

Script:

local brick = script.Parent 
local deb = false 
function onClicked(plr)
	if deb == false then 
		deb = true 
		for i,v in pairs(game.Players:GetPlayers()) do 
		local PlayerGui = v.PlayerGui 
		PlayerGui.Fade.Frame.Visible = true 
		PlayerGui.Fade.Frame.BackgroundTransparency = 0.9 
		wait(0.1) 
		PlayerGui.Fade.Frame.BackgroundTransparency = 0
        wait(3)
        for i = .1,1,.1 do
        PlayerGui.Fade.Frame.BackgroundTransparency = i
        wait(.1)
		PlayerGui.Fade.Frame.Visible = false
		deb = false 
        end
     end
   end
end
script.Parent.mouseClick:connect(onClicked)

1 comment

0

Line 6, you're putting it inside eveyone's gui.

1 answer

✓ Accepted answer

So, this is how I did it.

local brick = script.Parent
local cD = script.Parent.ClickDetector
local deb = false

cD.MouseClick:Connect(function(hit)
	if hit:IsA("Player") and deb == false then
		deb = true
		local player = game:GetService("Players"):FindFirstChild(hit.Name)
		local playerGui = player:WaitForChild("PlayerGui")
		playerGui.Fade.Frame.Visible = true
		playerGui.Fade.Frame.BackgroundTransparency = 0.9
		wait(0.1)
		playerGui.Fade.Frame.BackgroundTransparency = 0
		wait(3)
		for i = 0.1,1,0.1 do
			playerGui.Fade.Frame.BackgroundTransparency = i
			wait()
		end
		wait()
		playerGui.Fade.Frame.Visible = false
		deb = false
	end
end)

First, I set up the variables.

Next, I setup my function for when the player clicks the button and sets a variable equal to the player in the service Players.

After that, I just did what you did.

One thing is that for the for i loop, don't put the PlayerGui.Fade.Frame.Visible = false in there because it will go invisible after one millisecond and the animation won't play. Just a heads up. Same for the debounce, and I'd recommend using wait() instead of wait(0.1) because wait() runs more smooth. Or, you can go advanced and use RunService and do renderstepped and everytime a frame plays it decreases background transparency by 0.1, but yeah. I'd also recommend for when you do .1 to do 0.1 to make it easier when you're looking for 0.1. But, it's all up to you whether you want to do it or not.

Hope this helped, if it worked let me know and put this as an answer. If it didn't work, let me know so I can fix it and help you.

This is what the part looks like. (https://gyazo.com/181323788a05777da252a08cac1f4914)

2 comments

0

Thanks a ton! but would you mind helping me with another one of my questions? it is on my profile titled 'How do I properly make this anchor script use click detector?'

0

No problem! Will do!

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