Any reason as to why this doesnt work?

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 :frowning: 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
	if Seat.Occupant == nil then
		ui.Enabled = false


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
        if currentOccupant then
            currentOccupant:WaitForChild("PlayerGui"):WaitForChild("Bet").Enabled = false
            currentOccupant = nil

1 Like

Dude, @Fizzy you do this all the time, Iā€™m about to reply and I see you have already answered with the correct code :slight_smile:

Sorry i let you wait long for a response, i will try it out and see if it works

This absolutely worked how i wanted it to work, thank you so so so much

1 Like

Haha, I get a little overzealous sometimes. I guess watching my solution count go up is satisfying, in a way.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.