Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont my Airport Card Door GUI work?

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

2 answers

✓ Accepted answer

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)

4 comments

0

so I change local player to that location and make local player = game.Players.LocalPlayer? And what do you mean by "get player character here" that whole thing confuses me.

0

You don't use LocalPlayer at all; instead, you use game.Players:GetPlayerFromCharacter(character). I don't know how you would find the character, though; if you need help, post a screenshot of the character hierarchy.

0

ok sorry im a little confused, what do I put in (character)

1

What zenith is saying is that, you can't use the phrase "game.Players.LocalPlayer" in a normal script. You can only use that in a local script.

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 :)

This discussion is preserved as it was. New answers, comments, and votes are closed.