Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Check if true then set other bool true. ?

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

✓ Accepted answer

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.

1 comment

0

Thanks for the help :-)

This discussion is preserved as it was. New answers, comments, and votes are closed.