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

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

Asked by
130363 67
7 years ago
Edited 7 years ago

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

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 OldPalHappy 1477 — 7y
0
Do I use something like else if or if or while true do 130363 67 — 7y
0
I am confused how do I implement in my script???? 130363 67 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

0
:c OldPalHappy 1477 — 7y
0
:c superalp1111 662 — 7y
0
:c 130363 67 — 7y
Ad

Answer this question