I made a gui that is in starterGui and has nothing, but a frame in it. The gui pops up on touched, but the problem is, is that it's showing up on everyone elses screen. The code is in a local script inside of the screenGui. I'm stuck on what to do.
partTest = game.Workspace.TestTOuchy gui = script.Parent partTest.Touched:Connect(function(hit) if (hit.Parent:FindFirstChild("Humanoid")~= nil) then script.Parent.Enabled = true wait(2) script.Parent.Enabled = false end end)
Explanation
This is due to how you just detect if a part was touched. This would result in all of the LocalScripts detecting that it was touched even if it was another player.
The Solution
An easy fix for this is to create a RemoteEvent in ReplicatedStorage so that the part can send the open gui request to specific players. Below is the code that would help:
Script in the Part:
local guiEvent = Instance.new("RemoteEvent", game.ReplicatedStorage) guiEvent.Name = "guiEvent" script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) guiEvent:FireClient(player) end end)
LocalScript in the Gui:
local guiEvent = game.ReplicatedStorage:WaitForChild("guiEvent") guiEvent.OnClientEvent:Connect(function() script.Parent.Enabled = true wait(2) script.Parent.Enabled = false end)
That should fix your problem!
If you have any other questions, just reply to this answer! :)
-Crystal
When partTest is touched by any Player's character, the body of the if statement will execute. I assume this is not your desired result, as you want the body to execute only if the local Player touches partTest.
We can use Players:GetPlayerFromCharacter
to check if the character that touched partTest belongs to the local Player. If this isn't the case, do not enable the GUI.
local players = game:GetService("Players") local local_player = players.LocalPlayer local partTest = workspace.TestTOuchy local gui = script.Parent partTest.Touched:Connect(function(hit) -- Check if the Player (or nil) returned from the function is not the local Player. if players:GetPlayerFromCharacter(hit.Parent) ~= local_player then return end gui.Enabled = true wait(2) gui.Enabled = false end)