Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to make a GUI appear when the Localplayer is sitting down?

Asked by 4 years ago

Hello, I am trying to make a GUI appear when the Localplayer is sitting down. I currently have the Localscript placed in the frame of the GUI. So I am trying to make it so when it detects that the player is sitting down it will make the frame visible. I've tried writing a script that does this but doesn't seem to work. it doesn't even display any errors it just doesn't work.

Here is the script

wait(3)
local w = game.Players.LocalPlayer.Character.Humanoid
local d = game.Players.LocalPlayer.PlayerGui.work.Frame
---------------------------------------------
if w.Sit == true then
    d = true
elseif w.Sit == false then
    d.Visible = false
end

Can anyone help

1 answer

Log in to vote
0
Answered by
0_2k 496 Moderation Voter
4 years ago
Edited 4 years ago

If this is a seat you're attempting to sit in, It'd go like this

-- Regular Script inside of the seat

players = game:GetService("Players")
seat = script.Parent
active = false
plr = nil

seat.ChildAdded:Connect(function(child) -- event for the seat
    if not active then -- ensuring this check is false if they are standing
        if child.Name == "SeatWeld" then -- finding the weld
            active = true
            plr = players:GetPlayerFromCharacter(child.Part1.Parent)
            if plr ~= nil then -- ensuring its a player
                plr:WaitForChild("PlayerGui").work.Frame.Visible = true -- your result
            end
        end
    end
end)

seat.ChildRemoved:Connect(function(child)
    if child.Name == "SeatWeld" then
        if active == true then
            active = false
            wait()
            plr:WaitForChild("PlayerGui").work.Frame.Visible = false
        end
    end
end)
Ad

Answer this question