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

The script doesn't work when I want the script to check if is true then something will happen?

I want the script to check if NPC is sit is true then wait a few seconds then makes the NPC jump. But it looks right to me but it doesn't work. The appreciated you help.

local v = script.Parent.Parent:findFirstChild("Humanoid")

if v.Sit then
	wait(7)
	v.Jump = true
end

Please don't post hateful comments I am just a kid who wants and is trying to learn Lua

3 comments

0

The problem is the if statement only runs once at the beginning of the script, and never again. You'll need to find a way of checking this statement multiple times. You could do this with a loop or with events. However, I suggest using this simple event: http://wiki.roblox.com/index.php?title=API:Class/Humanoid/StateChanged

0

Do I use something like else if or if or while true do

0

I am confused how do I implement in my script????

1 answer

As OldPalHappy says you can use StateChanged event of Humanoid. However since I am not professional on it I will suggest Changed event :) I do not know if you know functions or events yet, but here's an example for you.

v = script.Parent.Parent:findFirstChild("Humanoid")

--First of all, let's create a function
function PropertyChanged()
	--Now the if condition
	if v.Sit then
		wait(7)
		v.Jump = true
	end
end

--For sure, do not forget about connecting function to an event. 
v.Changed:connect(PropertyChanged)

This code will start PropertyChanged function each time a property of script changes, including Sit.

3 comments

0

:c

0

:c

0

:c

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