The door itself opens, but the GUI doesn't appear. Here's the main code.
local door1 = script.Parent.Parent.Door1 local door2 = script.Parent.Parent.Door2 local walkforwardgui = script.Parent.Parent.HitDetector.WalkforwardGUI local player = game.Players.LocalPlayer script.Parent.Touched:Connect(function(hit) if hit.Parent.Name == "Eco" or hit.Parent.Name == "FC" then door1.CanCollide = false door1.Transparency = 1 door2.CanCollide = false door2.Transparency = 1 wait(3) door1.CanCollide = true door1.Transparency = 0 door2.CanCollide = true door2.Transparency = 0 local walkforwardguiclone = walkforwardgui:Clone() walkforwardgui.Parent = player.PlayerGui walkforwardgui.Main.Visible = true walkforwardgui.Main.Text.Text = "Walk forward, "..player.Name end end)
https://www.screencast.com/t/nffWdEpXHW < Explorer screenshot
The reason why this code doesn't work is that you reference game.Players.LocalPlayer
in a server-side Script. The aforementioned reference only works in client-side scripts (LocalScript). To fix this, use this:
local door1 = script.Parent.Parent.Door1 local door2 = script.Parent.Parent.Door2 local walkforwardgui = script.Parent.Parent.HitDetector.WalkforwardGUI script.Parent.Touched:Connect(function(hit) if hit.Parent.Name == "Eco" or hit.Parent.Name == "FC" then door1.CanCollide = false door1.Transparency = 1 door2.CanCollide = false door2.Transparency = 1 wait(3) door1.CanCollide = true door1.Transparency = 0 door2.CanCollide = true door2.Transparency = 0 local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent) local walkforwardguiclone = walkforwardgui:Clone() walkforwardgui.Parent = player.PlayerGui walkforwardgui.Main.Visible = true walkforwardgui.Main.Text.Text = "Walk forward, "..player.Name end end)
The reason that your code doesn't work is because the script is not a local script and game.Players.LocalPlayer
is only used in local scripts.
You should use hit.Parent.Parent
and then use GetPlayerFromCharacter()
.
When you say hit.Parent.Parent
, that means get the model of the player, which is in the Workspace. To get the player, which is in the 'Players' service we use GetPlayerFromCharacter
. The 'Character' is the model of the player in the workspace, that includes the physical objects such as face, torso, arms and legs etc. The Player in the Player service has the PlayerGui, Backpack, etc which the character doesn't has.
Here is the fixed script(hopefully):
local door1 = script.Parent.Parent.Door1 local door2 = script.Parent.Parent.Door2 local walkforwardgui = script.Parent.Parent.HitDetector.WalkforwardGUI script.Parent.Touched:Connect(function(hit) if hit.Parent.Name == "Eco" or hit.Parent.Name == "FC" then local playerCharacter = hit.Parent.Parent -- Get the character of the player local player = game.Players:GetPlayerFromCharacter(playerCharacter) --Get the player door1.CanCollide = false door1.Transparency = 1 door2.CanCollide = false door2.Transparency = 1 wait(3) door1.CanCollide = true door1.Transparency = 0 door2.CanCollide = true door2.Transparency = 0 local walkforwardguiclone = walkforwardgui:Clone() walkforwardgui.Parent = player.PlayerGui walkforwardgui.Main.Visible = true walkforwardgui.Main.Text.Text = "Walk forward, "..player.Name end end)
I hope this answers your question and also fixes your problem, if it does then don't forget to mark this question solved :)