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

Check if true then set other bool true. ?

Asked by
130363 67
7 years ago
Edited 7 years ago

I want the script to check if the (NPC)Humanoid.Sit is true then it will jump. So it will get out of sit. If you can provide the example or tell me in a way to understand for beginning lua coders

local Plyr = script.Parent

while true do
    Plyr.StateChanged:connect(function(state)
        if state == Enum.HumanoidStateType.Seated then
            Enum.HumanoidStateType.Jumping = true
        end
        wait()
    end)
    wait()
end
wait()

1 answer

Log in to vote
2
Answered by 7 years ago

This is a simple task to do using the event Seated then setting the sit value of the humanoid to false, you can also use jump.

In your code you have use a loop which will connect a new function each time which is bad as we only need one function to do the job.

The StateChanged has two args the old state and the new state, you check the old state when we need its new state. Lastly you need to make the humanoid jump an Enum is just a data type and will not make the humanoid jump, only the humanoid can make itself jump.

Example:-

local humanoid= script.Parent.Humanoid -- the humanoid

humanoid.StateChanged:Connect(function(state, newState) -- we check the new state
    print(newState)
    if newState == Enum.HumanoidStateType.Seated then
        humanoid.Jump = true -- we also need to make the humanoid jump 
    end
end)

As we have the seated event it would be best to use it because it will fire only when the humanoid sits which is what we need.

Example:-

local humanoid = script.Parent.Humanoid

humanoid.Seated:Connect(function(active, seatPart)
    humanoid.Sit= false-- You can also set sit to false, I also think this looks better ingame
end)

I hope this helps.

0
Thanks for the help :-) 130363 67 — 7y
Ad

Answer this question