So my game needs a feature where a gui is toggled when the player is sitting. Depending on what the player is sitting on, the gui will be different. One of the gui will allow the player to select certain test taking challenge IF the player meets certain stat requirements. When they select a challenge in the gui, the client will trigger a remote event for the server to do several things. If the player presses spacebar, they will get a prompt to abandon the challenge.
Right now I have this in a local script
local RunService = game:GetService("RunService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Sitting = false
RunService.Heartbeat:Connect(function(delta)
if Humanoid.Sit and (not Sitting) then
print("Sat down, toggling gui")
Sitting = true
elseif not(Humanoid.Sit) and Sitting then
print("got up, toggling gui")
Sitting = false
end
end)
Is this the best way to check if the player is sitting and toggle a gui? I will be cloning elements from replicated storage as each gui will be different. I’m worried about having the player sit down and then the gui not toggling properly, causing the player to be stuck.