Button still visible for everyone?

  1. What do you want to achieve?
    ~ I want a text button that only I can see.

  2. What is the issue?
    ~ In studio test play with multiple players, no one has the button.
    If I publish the game and drop myself and my alt in, both of us have the button.

  3. What solutions have you tried so far?
    ~ Tried searching but not really getting anywhere.

As far as I can tell, I should be the only one that sees the button.
Here is the script…

local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("ActivateGlobalParticleEmitter")

for i, v in pairs(game.Players:GetPlayers()) do
	if v.Name == "LottaPitchy" then 
		script.Parent.Visible = true
	else
		script.Parent.Visible = false
		end
		
		button.MouseButton1Click:Connect(function()
			remoteEvent:FireServer(player)
	end)
end

The button is set to visible - false in properties.
It was set to true, but that was still the same.

What am I missing?

1 Like

Instead of trying to loop through the players, you should instead make use of

game.Players.LocalPlayer

To get what you want, you should be able to do:

local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("ActivateGlobalParticleEmitter")

if game.Players.LocalPlayer.Name == "LottaPitchy" then
    script.Parent.Visible = true
else
    script.Parent.Visible = false
end
button.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(player)
end)

Couple of points regarding this:

  • The addition of the else script.Parent.Visible = false end is probably not neccesary, but I added it just in case you forget to change the visibility to false in Studio.

  • Instead of going off of username, you should go off of UserId in case you end up changing your username on Roblox. However, for now it should be fine.

  • Ensure that you either check that the person who fired the remote event is yourself (so exploiters can’t triger it).

  • In the future, you should instead clone the UI from a server location to the PlayerGUI if the player is yourself, so that exploiters can’t make the UI visible and access it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("ActivateGlobalParticleEmitter")

task.wait()

if game.Players.LocalPlayer.Name == "LottaPitchy" then
        button.Visible = true
else
end

button.MouseButton1Click:Connect(function()
			remoteEvent:FireServer(player)
end)

should work, you dont need to loop, I believe the loop is going through every player, eventually running the loop through your name on other players client making it visible for others, localplayer is the easiest way to do this though.

oh mb lol, accidentally redid ur script. give this guy the solution if it works lol

So

if game.Players.LocalPlayer.UserId == "BunchOfNumbersHere" then

?
I’m so bad at scripting.

~ The button is set to false already, but I’ll leave that in in case I have a “moment” and forget it’s SUPPOSED to be false.

~ Are exploiters going to cause an issue? Like, if an exploiter gets in, is the worst thing they’re going to do there the equivalent of pressing the button? If so all they’re going to do is start a particle emitter at the wrong time which will be annoying but not a disaster.
I should look more into how to do this I think, to protect future endeavours.

Thank you so much for your help, again :slight_smile:

No bad, I appreciate the help :slight_smile:

Unfortunately, it’s still not working… Now I don’t see the button either…

Studio hates me :upside_down_face:

Maybe remove the else, other than that are there any errors?

So this is what I have now…

local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("ActivateGlobalParticleEmitter")

if game.Players.LocalPlayer.Name == "LottaPitchy" then
	script.Parent.Visible = true
end

button.MouseButton1Click:Connect(function()
	remoteEvent:FireServer(player)
end)

I have no errors or warnings in the output, but the button is not visible.

(player) in the last line has a red squiggle under it, if that’s relevant…?

add the task.wait() at the top so it makes sure the script runs when stuff loads, you can make it task.wait(2) to be sure, also player is underlined because you haven’t defined the variable. if i remember correctly player is an automatic parameter, meaning you dont have to add the player its automatically added to the remoteevent.OnServerEvent() or whatever the function is

Fair point… I guess I hadn’t realised I don’t normally define the player before.

Added the task.wait. Still not working and still no output error…

Maybe I try making it visible in properties and add the else back in… Let’s see if that does anything.

Well.

So, it works, and I gave you Jelq the solution because you both fixed it and I gave Poppy the solution on my last car crash.

So it turns out, this probably would have worked a whole lot quicker if I hadn’t disabled the parent screenGui… :confounded:

My oops… But, it definitely works now exactly as I wanted and that’s another thing checked off, so thank you (both) very much :slight_smile:

Going to go and work on the other stuff Poppy mentioned and see how that goes.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.