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

I edited a script from the developer forum and it's not working how do I fix it?

I edited a script from the developer forum and I want it to show a GUI when the player sits down and it disappears when the player gets up, and the script isn't working.

local Players = game:GetService("Players")

local seat = script.Parent

local currentPlayer = nil

seat:GetPropertyChangedSignal("Occupant"):Connect(function() local humanoid = seat.Occupant if humanoid then local character = humanoid.Parent local player = Players:GetPlayerFromCharacter(character) if player then game.StarterGui.ComputerGUI.Frame.Visible = true currentPlayer = player return end end if currentPlayer then game.StarterGui.ComputerGUI.Frame.Visible = false currentPlayer = nil end end)

local Players = game:GetService("Players")

local seat = Instance.new("Seat")
seat.Anchored = true 
seat.Position = Vector3.new(-111.57, 6.845, 3.845)
seat.Size = Vector3.new(1.98, 0.23, 1.93)
seat.Material = Enum.Material.Wood
seat.BrickColor = BrickColor.new("Dark orange")
seat.TopSurface = "Smooth"
seat.BottomSurface = "Smooth"
seat.Parent = workspace 

local currentPlayer = nil

**seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local humanoid = seat.Occupant 
	if humanoid then 
		local character = humanoid.Parent
		local player = Players:GetPlayerFromCharacter(character)
		if player then 
		game.StarterGui.ComputerGUI.Frame.Visible = true
			currentPlayer = player
			return
		end	
	end
	if currentPlayer then 
	game.StarterGui.ComputerGUI.Frame.Visible = false
		currentPlayer = nil
	end
end)**

1 comment

0

Please fix your code blocks.

1 answer

✓ Accepted answer

Hello.

The reason as to why your GUI isn't showing, is because you are trying to tell the script to make a frame in a GUI in StarterGui, instead of PlayerGui.

Why are these two different?

Well, it should be pretty self explanatory. From the title StarterGui, we can tell that this is used to clone all the GUIs set into StarterGui, to the clients' PlayerGui. StarterGui, in a simple way, is used to clone all the StartingGuis put into the StarterGui, to the player. PlayerGui, in the other hand, is the client's GUI handler, and this keeps all the GUIs for that specific player, making them editable and what not.

Why would this make a difference?

Well, like stated before, changes in GUIs in StarterGui will not make a difference to any of the players, as it's not connected to them in any way or form. For that reason, we use the PlayerGui to which is connected to the player and is editable.

So now, to apply the changes to your script, it's as simple as changing the game.StarterGui to the Player.PlayerGui instead.

Fixed script:

local Players = game:GetService("Players")
local Seat = script.Parent

local CurrentPlayer = nil

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local Humanoid = Seat.Occupant
	if Humanoid then 
		local Character = Humanoid.Parent 
		local Player = Players:GetPlayerFromCharacter(Character) 
		if Player then
			Player.PlayerGui.ComputerGUI.Frame.Visible = true
			CurrentPlayer = Player return end 
		end
		if CurrentPlayer then
		CurrentPlayer.PlayerGui.ComputerGUI.Frame.Visible = false CurrentPlayer = nil
	end
end)

local Players = game:GetService("Players")

local Seat = Instance.new("Seat")
Seat.Anchored = true 
Seat.Position = Vector3.new(-111.57, 6.845, 3.845)
Seat.Size = Vector3.new(1.98, 0.23, 1.93)
Seat.Material = Enum.Material.Wood
Seat.BrickColor = BrickColor.new("Dark orange")
Seat.TopSurface = "Smooth"
Seat.BottomSurface = "Smooth"
Seat.Parent = workspace 

local CurrentPlayer = nil

	Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local Humanoid = Seat.Occupant 
	if Humanoid then 
		local Character = Humanoid.Parent
		local Player = Players:GetPlayerFromCharacter(Character)
		if Player then 
			Player.PlayerGui.ComputerGUI.Frame.Visible = true
			CurrentPlayer = Player
			return
		end 
	end
	if CurrentPlayer then 
		CurrentPlayer.PlayerGui.ComputerGUI.Frame.Visible = false
		CurrentPlayer = nil
	end
end)

Hope this helps!

1 comment

0

Thank you! This helps a lot!

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