local char = game.Players.LocalPlayer.Character
char.Humanoid.Seated:Connect(function()
if script.Value.Value==false then
print("PPPP")
script.Value.Value = true
local e=script.ScreenGui:Clone()
e.Parent = game.Players.LocalPlayer.PlayerGui
e.Enabled = true
e.LocalScript.Disabled = false
end
end)
this is my scipt, using waitforchild for characters yields infinite yield,
using repeat wait() until findfirstchild character yields nothing/nil
@RudraVII@slothfulGuy
Both of your ways are not reccomended, as @Quackers337’s answer of local char = player.Character or player.CharacterAdded:Wait() is the recommended way.
Actually, that’s how you are more or less supposed to reference the character. Review the answer before posting.
Back to the topic, I will highlight the mistakes:
local char = game.Players.LocalPlayer.Character -- The player is loaded before the character, so doing this might return nil
char.Humanoid.Seated:Connect(function() -- Will error if the character is nil
if script.Value.Value==false then -- Try renaming the bool value to another name
print("PPPP")
script.Value.Value = true
local e=script.ScreenGui:Clone()
e.Parent = game.Players.LocalPlayer.PlayerGui
e.Enabled = true
e.LocalScript.Disabled = false
end
end)
This is a fixed script:
local player = game.Players.LocalPlayer
local char = player.Character
if not char then
char = player.CharacterAdded:Wait()
end
local Humanoid = char:WaitForChild("Humanoid")
char.Humanoid.Seated:Connect(function()
if script.Value.Value==false then
print("PPPP")
script.Value.Value = true
local e=script.ScreenGui:Clone()
e.Parent = game.Players.LocalPlayer.PlayerGui
e.Enabled = true
e.LocalScript.Disabled = false
end
end)
Even if it works, it’s not really an excuse to be reinventing the wheel or foregoing proper practice. There’s a lot that “works” yet isn’t proper or has better methods of going about doing something. Quackers suggested the proper way to do this and you should. Unnecessarily creating loops is a bad habit and less performant than relying on an event-based system.
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Seated:Connect(function()
if script.Value.Value == false then
print("PPPP")
script.Value.Value = true
local e = script.ScreenGui:Clone()
e.Parent = game.Players.LocalPlayer.PlayerGui
e.Enabled = true
e.LocalScript.Disabled = false
end
end)
Note that I also did a :WaitForChild() to get Humanoid, to prevent errors from that too.