Need help displaying this script to only the player activating it

Hello DevForum!

I’m a new developer who isn’t familiar with scripts at all, and can make some pretty embarrassing mistakes, and one of them is this. All help I’ve tried getting didn’t work, either due to my issues understanding the scripts or the issues with my questions.

I’ve been trying to make a script which makes some GUI’s visible once an object is touched by the player.

This works flawlessly, until you test it with more players, and you clearly see that every single person in the server gets the same GUI popup. This is not what I want, I would like only the person who touched this object to get this popup.

Here’s the portion of the LocalScript (inside of the StarterGui hierarchy)

front.Touched:Connect(function(hit)
		wait(0.5)
		script.Parent.Parent.Parent.TextButton.Visible = true
		script.Parent.Parent.Visible = true
		while true do
			wait(1)
			workspace.beep:Play()
			script.Parent.Parent.Text = label.Text

I have tried doing some PlayerGui things, and getting the script out of the StarterGui in addition or something, but none of it has worked.

(If it’s any different, I’d also like to know to get the “workspace.beep” in there to play only to the player who touched the part, like the rest of the script, because that displays to everyone too)

I will appreciate any sort of assistance at all, and if you need any more information about these circumstances, I will do my best to provide it. Thanks!

You could use the FireClient method which has a parameter of the player in question. You need to use a RemoteEvent for this method to be able to be called. An example in your case could be something like…

local Players = game.Players
front.Touched:Connect(function(hit)
    local Player = Players:GetPlayerFromCharacter(hit.Parent)
    if Player then
        wait(0.5)
        YOURREMOTEEVENT:FireClient(Player)
        --...
    end
    
end)

EDIT: I would caution you though that once it is no longer touching, you may need to fire another event to disable it as well.

Basically: you are Creating an Event for the Player Only, anything that touches the Part for the Client would result in it being fired, so when a Player (who maybe also has the same exact event connected) steps on the Object with the .Touched Event, would also fire. Which will give you, and them the exact same result as you both have the same connection connected to the part, which does the same thing.

The Best thing would be to fire using a RemoteEvent like what @ConfidentLetter Provided.

I’m sorry, but would it be okay for more information about how formatting this option would work? As I said, I’m new to scripting and have tried many options similar to this that either don’t pull up the GUI or still don’t fix my problem.

You should look into RemoteEvents. They are incredibly useful.

Considering the fact that this is inside a local script, I’m not sure you can fire a client on the client so I recommend switching your Touched function to a server script and to have your connection be in the StarterGui.

The documentation does cover FireClient pretty well so read up on it and make sure you pass in the Player parameter when you call the function.

Yet, Incredibly Vunerable.

That is if you don’t do the necessary checks.

Which are called “Sanity Checks”, and they arent fully secure either.

Not much else you can do except hope Roblox does something :person_shrugging:

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