Hi ppl,
im trying to make a gui appear when the player seats on a seat and dissapear if he goes off of the seat. I made a local script in a model as u can see here under.
It doesnt work can someone help me?
local model = script.Parent
local Seat = model:WaitForChild("Plr1")
local char = game.Players.LocalPlayer.Character
local plr = game.Players.LocalPlayer
local human = char:FindFirstChildWhichIsA("Humanoid")
local ui = plr.PlayerGui:WaitForChild("Bet")
local function Seated()
if Seat.Occupant ~= nil then
ui.Enabled = true
end
if Seat.Occupant == nil then
ui.Enabled = false
end
end
Seat:GetPropertyChangedSignal("Occupant"):Connect(Seated)
This would normally work, however, since you placed the LocalScript in the Workspace, it will not run.
Make a server script instead and try this snippet:
local players = game:GetService("Players")
local model = script.Parent
local seat = model:WaitForChild("Seat")
local currentOccupant = nil
local function seated()
if seat.Occupant then
currentOccupant = players:GetPlayerFromCharacter(seat.Occupant.Parent)
if currentOccupant then
currentOccupant:WaitForChild("PlayerGui"):WaitForChild("Bet").Enabled = true
end
else
if currentOccupant then
currentOccupant:WaitForChild("PlayerGui"):WaitForChild("Bet").Enabled = false
currentOccupant = nil
end
end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(seated)