is it possible to popup a gui when a player seated on a seat?
First, two search terms have threads with a topic related to this question:
Add a seat object to Workspace, and insert a script and paste this code. Also, add the Gui you would like to clone into ServerStorage. Let me know how it goes!
--Insert GUI into ServerStorage
local ServerStorage = game:GetService("ServerStorage")
local seatGui = ServerStorage:WaitForChild("NameOfGui") --- Change to the name of GUI
local Players = game:GetService("Players")
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
if script.Parent.Occupant then
local plr = Players:GetPlayerFromCharacter(script.Parent.Occupant.Parent)
local plrGui = plr:FindFirstChild("PlayerGui")
if plrGui then
local guiClone = seatGui:Clone()
guiClone.Parent = plrGui
end
end
end)
What if i want the gui to disappear when a player leaves the seat
If you want to remove the UI when the player gets up, I would try this a bit differently:
-- Identify
local ServerStorage = game:GetService("ServerStorage")
local seatGui = ServerStorage:WaitForChild("Name of your UI") -- Change to name of your UI
local Players = game:GetService("Players")
local CurrentOccupant = nil
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
if script.Parent.Occupant then
local plr = Players:GetPlayerFromCharacter(script.Parent.Occupant.Parent)
CurrentOccupant = plr
local plrGui = plr:FindFirstChild("PlayerGui")
if plrGui then
local guiClone = seatGui:Clone()
guiClone.Parent = plrGui
end
else
local verify = CurrentOccupant:FindFirstChild("PlayerGui")
if verify then --player has not left the game
local Object = CurrentOccupant.PlayerGui:FindFirstChild("Name of your UI") -- Change to name of your UI
Object:Destroy()
CurrentOccupant = nil
else --player has left the game
CurrentOccupant = nil
end
end
end)
I believe this would work, however, I am not sure, I didn’t test it, so let me know if I made a typo.
14:46:28.575 - Workspace.GuiPopuponSeated.Script:15: attempt to index nil with 'FindFirstChild'
14:46:28.576 - Stack Begin
14:46:28.578 - Script 'Workspace.GuiPopuponSeated.Script', Line 15
14:46:28.579 - Stack End
i got an error when i tried this script
I just tested his script and it works. You probably forgot to edit the “Name of your UI” on lines 3 and 19.
Another way would be to add this local script on StarterCharacterScripts but @ijvyce 's code works just fine!
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local humaoid = script.Parent:FindFirstChildWhichIsA("Humanoid")
humaoid:GetPropertyChangedSignal("Sit"):Connect(function()
if humaoid.Sit == false then
local plrGui = plr:FindFirstChild("PlayerGui")
local sitGui = plrGui:FindFirstChild("NameOfGui")
if sitGui then
sitGui:Destroy()
end
end
end)
You’re right, except if the player sits in a chair that isn’t one where a UI should pop up. At that point it’s easier just to specify individual seats as I did.
local boySeat = script.Parent.Boy
local girlSeat = script.Parent.Girl
local Players = game:GetService("Players")
local boyCurrentOccupant = nil
local girlCurrentOccupant = nil
boySeat:GetPropertyChangedSignal("Occupant"):Connect(function()
girlSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
if boySeat.Occupant and girlSeat.Occupant then
print("Franx Activated")
local boyPlr = Players:GetPlayerFromCharacter(boySeat.Occupant.Parent)
local boyPlrGui = boyPlr:FindFirstChild("PlayerGui")
boyCurrentOccupant = boyPlr
boyPlrGui.SoloModeAnimalFranx.AnimalFranxButton.Visible = false
for i,v in pairs(boyPlrGui.TwoPlayerFranx.Skills:GetChildren()) do
v.Disabled = false
end
local girlPlr = Players:GetPlayerFromCharacter(girlSeat.Occupant.Parent)
local girlPlrGui = girlPlr:FindFirstChild("PlayerGui")
girlCurrentOccupant = girlPlr
girlPlrGui.SoloModeAnimalFranx.AnimalFranxButton.Visible = false
for i,v in pairs(girlPlrGui.TwoPlayerFranx.Skills:GetChildren()) do
v.Disabled = false
end
else
local boyVerify = boyCurrentOccupant:FindFirstChild("PlayerGui")
if boyVerify then --player has not left the game
for i,v in pairs(boyCurrentOccupant.PlayerGui.TwoPlayerFranx.Skills:GetChildren()) do
v.Disabled = true
end
else --player has left the game
boyCurrentOccupant = nil
end
local girlVerify = boyCurrentOccupant:FindFirstChild("PlayerGui")
if girlVerify then --player has not left the game
for i,v in pairs(girlCurrentOccupant.PlayerGui.TwoPlayerFranx.Movement:GetChildren()) do
v.Disabled = true
end
else --player has left the game
girlCurrentOccupant = nil
end
end
end)
end)
Its working but the skill is still activated even though a player left the seat
@ijvyce @Vezipe There’s a much simpler way to do this.
In a LocalScript under StarterCharacterScripts:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local Gui = Player.PlayerGui.Gui
Humanoid.Seated:Connect(function(active, seat)
Gui.Enabled = active
end)
what i want here is to disable the skills from the boy player and the movement from girl player when one or more of them left the seat
That will happen when they sit period. In any seat. What if @sktvladimir535 wants it to only happen to specific seats? Then that would not work and it’s better to go serverside.
Then index the seat property which is the second argument passed in the function.
This said when seated on a seat, so while he could mean one particular seat, he could also mean seated on any seat.
Right, but now I’m seeing from context he’s trying to interact with another seat.
I found out the answer to my problem thanks for your help yall this is the final script
local boySeat = script.Parent.Boy
local girlSeat = script.Parent.Girl
local Players = game:GetService("Players")
local boyCurrentOccupant = nil
local girlCurrentOccupant = nil
boySeat:GetPropertyChangedSignal("Occupant"):Connect(function()
girlSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
if boySeat.Occupant and girlSeat.Occupant then
print("Franx Activated")
local boyPlr = Players:GetPlayerFromCharacter(boySeat.Occupant.Parent)
local boyPlrGui = boyPlr:FindFirstChild("PlayerGui")
boyCurrentOccupant = boyPlr
game.ReplicatedStorage.Boy:FireClient(boyPlr)
for i,v in pairs(boyPlrGui.TwoPlayerFranx.Skills:GetChildren()) do
v.Disabled = false
end
local girlPlr = Players:GetPlayerFromCharacter(girlSeat.Occupant.Parent)
local girlPlrGui = girlPlr:FindFirstChild("PlayerGui")
girlCurrentOccupant = girlPlr
game.ReplicatedStorage.Girl:FireClient(girlPlr)
for i,v in pairs(girlPlrGui.TwoPlayerFranx.Movement:GetChildren()) do
v.Disabled = false
end
else
local boyVerify = boyCurrentOccupant:FindFirstChild("PlayerGui")
if boyVerify then --player has not left the game
for i,v in pairs(boyCurrentOccupant.PlayerGui.TwoPlayerFranx.Skills:GetChildren()) do
v.Disabled = true
end
else --player has left the game
boyCurrentOccupant = nil
end
local girlVerify = girlCurrentOccupant:FindFirstChild("PlayerGui")
if girlVerify then --player has not left the game
for i,v in pairs(girlCurrentOccupant.PlayerGui.TwoPlayerFranx.Movement:GetChildren()) do
v.Disabled = true
end
else --player has left the game
girlCurrentOccupant = nil
end
end
end)
end)
In your script for the girl verify, it should be girlCurrentOccupant not boyCurrentOccupant
Whoops, you just got it! Be sure to mark the solution.