I've recently made a script that is placed into a part. The script is supposed to make it so whenever you touch the part with your character it enables the visibility of a gui that every player starts out with. I'd also like to note that the gui's visibility is set to false by default. The script works as planned the first time but when I close the gui and touch the part again it does not reappear like I want it to. The gui has a "close" button that just sets the visibility back to false so It should be reappearing when touching the part again. Here is the script:
local Part = script.Parent Part.Touched:connect(function(HIT) local H = HIT.Parent:FindFirstChild("Humanoid") if H then local Player =game.Players:GetPlayerFromCharacter(HIT.Parent) Player.PlayerGui.Glowsticks.Frame.Visible = true end end)
Here is the close button localscript inside the gui:
function onButtonClicked() script.Parent.Parent.Visible = false end script.Parent.MouseButton1Click:connect(onButtonClicked)
Try firing a remote event for a client that touches the part and get the player by that event.
Or to be more precise:
local Part = script.Parent Part.Touched:connect(function(HIT) local H = HIT.Parent:FindFirstChild("Humanoid") if H then local Player =game.Players:GetPlayerFromCharacter(HIT.Parent) game.ReplicatedStorage.RemoteEvent:FireClient(Player) --Fire this event on touch end end)
In Localscript:
plr = game.Players.LocalPlayer game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() --plr is the player that touched the part. plr.PlayerGui.Glowsticks.Frame.Visible = true end) function onButtonClicked() script.Parent.Parent.Visible = false end script.Parent.MouseButton1Click:connect(onButtonClicked)