Help with script - When player touches a part a gui appears

So first of all I made an event in ServerScriptService to detect when the player touches the part

game.Workspace.PartToTouch.Touched:Connect(function(hit)
if game.Players.GetPlayerFromCharacter(hit.Parent) then
game.ReplicatedStorage.ShowGUI:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
end)

RemoteEvents are overkill for this since everything is client-sided, Correct me if i am wrong.

Then I made a local script to make the gui appear.
game.ReplicatedStorage.ShowGUI.OnClientEvent:Connect(function()

script.Parent.Frame.Visible = not script.Parent.Frame.Visible

end)
Can anyone help me to make it only appear once though?

You don’t need to run a Remote Event as it’s client sided, and GUI’s can be changed from clients because you want only the client to see the gui right?

Or if when 1 player touches it u want it to appear on everyone else’s screen?

Well I find remote events easier, they may be a overkill but I will still try it out.

I did kinda give you a solution to make it appear only one time but you shrugged it off.

No I only want it to appear on one player’s screen.

1 Like

First of all you don’t need a normal script,

Local script is enough,

in the local script write:

game.Workspace.PartToTouch.Touched:Connect(function(hit)
   if game.Players.GetPlayerFromCharacter(hit.Parent) then
      script.Parent.Frame.Visible = true
   end
end)

If you’re confused, Gui’s are meant to be only on one client’s screen, You can make it appear for all of them tho, but in this case you don’t want to

Thats why we are using local script to change the client’s screen

PS: Don’t change the local scripts location as u used before just change the script

Well can you give me more details where to put it and what other parts to use because I understand the script but don’t know where to use it.

Ok it is in the local script that is in the ScreenGui

30chars

Yeah keep the same old local script u used to show us ur example, remove the server script, and only change the text on the local script to what i’ve sent

He put the local script inside the frame so it’s easier to access it

Oh okay thats fine, just showing him the Debounce value as it works with the script I gave him earlier.

I don’t think debounce is necessary as he only wants turn turn it once

Your script will run every time the player touched the part. If he locally sets the debounce to true and checks for it, then it won’t run again. Alternatively, just destroy the script once he’s done with it locally.

True but it honestly depends on which game it is

Yes, once the player touches it once, the script never needs to run again.

2 Likes

Once they touch it, just add script:Destroy() to the end if it is local.

Horror type. The player has to enter the room and then my typewriting gui activates.