Basically the problem is that you are using the StarterGui.
StarterGui
This service, the content of it will get cloned locally into each player's PlayerGui. Say you have some GUIs in there, they all get cloned into the player's PlayerGui.
PlayerGui
The LocalScripts in this folder are the ones running and the GUIs the player sees and the ones they interact with are the ones all in PlayerGui. If you edit something in StarterGui the edit will be applied once the player resets.
So what was happening?
You weren't editing the player's PlayerGui GUI.
How do we fix this?
There are a few ways.
1. RemoteEvent
You would insert a RemoteEvent (preferably in ReplicatedStorage) and a localscript (preferably inside your frame)
The local script would be this:
local remoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
remoteEvent.OnClientEvent:Connect(function()
script.Parent.Visible = true
end)
In here it's listening for the OnClientEvent event of remote event. When it is fired by the server the code in the function will execute
And on the server side
local Players = game:GetService("Players")
local remoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
script.Parent.Touched:Connect(function(part)
local client = Players:GetPlayerFromCharacter(part.Parent)
if client then
remoteEvent:FireClient(client)
end
end)
Here it's just firing the remote event to the client who touches the part.
##2. Handle the touched event locally
I personally recommend this one, there will be that immediate feedback and you don't need the server doing any firing to the client
LocalScript, preferably in your frame
local part = game:GetService("Workspace").Part
local client = game:GetService("Players").LocalPlayer
part.Touched:Connect(function(other)
script.Parent.Visible = other:IsDescendantOf(client.Character)
end)
object:IsDescendant(ancestor) returns true if object is a descendant of ancestor, and when a player touched something it's a body part of their character; the leg, hand, ect.
So this is just assigning the Visible property to the return value of the function.
It is important that this is done because Touched can fire for anything touching it, another player, even a non player! So this is just to guarantee the local player touched it.
1 comment
Thanks for the help.