ScreenGui disabeling locally doesn't work

So I have a simple local script which should disable the screenGuis of the player that touches a part. NOTE that I want just the player that touches the part to see this change.

This is the code:

local plr = game.Players.LocalPlayer
local range = workspace:WaitForChild(“range3”)

range.Touched:Connect(function()
for i, v in pairs(plr:WaitForChild(“PlayerGui”):GetChildren()) do
if v:IsA(“ScreenGui”) then
v.Enabled = false
end
end
end)

Like I said, the code is simple, it is in a local script but it doesn’t work

Have a server-side Script under the part, and have it fire a RemoteEvent (in ReplicatedStorage) to tell the client to do whatever it is with the GUI.
I also noticed you aren’t checking if it is a player that touched the part, meaning it can fire on any touch.

Note: If this script is in the workspace, it will not run. A LocalScript will only run in:

  1. ReplicatedFirst
  2. StarterPlayerScripts
  3. StarterCharacterScripts
  4. StarterGui
  5. StarterPack

Note 2: Please format your scripts in the code format - it just makes it easier to read. You can do this with three backticks (`), or pressing the ‘</>’ button at the top of your post editor.

Thanks a lot, I was thinking to do the code in a remote event but I tought it is not necesary for this script. As well ty a lot for NOTE 2 because I didn’t know how to put scripts in code format. I’ll try it out.

1 Like