✓ Accepted answer
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
5 comments
Although this solution is valid, this can probably be handled completed from the client, see my answer :)
I appreciate the fast response! I completly forgot about using remote events.
Very true. I also believe that it's important to give the person as many options as possible. :)
yes, but i believe this solution is inferior due to the extra networking and latency that it will cause
if something can be done on the client without any negative effects, do it on the client