Hello everyone. I am pretty new to scripting and am having a bit of trouble with what I am trying to do. I attempted to make a button that will make the player who clicks it, sit down. The player will go flying down a pile of stairs. Here is my script:
local button = script.Parent
local plr = game.Workspace:FindFirstChild(âHumanoidâ)
button.MouseButton1Down:Connect(function(trip)
if trip then
plr.Sit = true
end
end)
When I press the button to trigger this script, it pops up in the output with âattempt to index nil with âSitââ.
Not really sure what to doâŚ
You arenât getting the playerâs humanoid. You are only looking for a humanoid inside the workspace. If this is a GUI, you need to get the playerâs character by doing this:
local LocalPlayer = game.Players.LocalPlayer
local character = LocalPlayer.Character
local Humanoid = character:WaitForChild("Humanoid")
Nevermind just noticed i was wrong your getting the humanoid incorrectly instead do this:
local button = script.Parent
local plr = game.Players.LocalPlayer
Button.MouseButton1Down:Connect(function()
local Character = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = Character and Character:FindFirstChild("Humanoid")
Humanoid.Sit = true
end)