script.Parent.Touched:Connect(function(hit) print "Door Touched" if hit.Parent:FindFirstChild("Humanoid") then game.StarterGui.DoorGui.Frame.Visible = true print "Gui Shown" end end)
For some reason, when a player comes in contact to the Door that is there, and its touched the frame doesn't show although its visibility is true
Basically the problem is that you are using the 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.
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.
You weren't editing the player's PlayerGui GUI.
There are a few ways.
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.
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 -- whatever your part is 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.
The reason for this is that you are modifying object in the StarterGui instead of in a Player's PlayerGui.
Everything inside the StarterGui is cloned in its current state to a player's PlayerGui when they join a game, so therefore, modifying the StarterGui would have no impact of that player's guis.
local plr = game.Player.LocalPlayer workspace.Thing.Touched:Connect(function(hit) if hit:IsDescendantOf(plr.Character) then plr.PlayerGui.DoorGui.Frame.Visible = true end end)
Note that the PlayerGui
is a child of the player object, and that I checked whether if the object that was hit was a descendant of the player's character, in order to prevent it from running when any other part or npc touched the part
Hopefuly this helped!