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

How do I make a code to keep checking a function?

Asked by 8 years ago

Im trying to make a script that will activate certain commands once a model is gone. It works when I test the game without the model to begin with, but when I test the game with the model and then remove it, the script wont activate the commands. Correct me if I'm wrong, but I think its because it only checks to see if the model is there or not one time in the beginning.

So I want to know how to code it to make it constantly check if it's there or not.

local disaster = workspace:FindFirstChild ("Disaster Script")
local humanoid = workspace:FindFirstChild("Soldier")
local serverStore = game:GetService("ServerStorage")

function Win()
    m = Instance.new("Hint")
    m.Parent = game.Workspace
    m.Text = "You Win! [Restarting...]"
    wait(5)
    m:Remove()
end

if humanoid == nil then
    disaster.Parent = serverStore   
    print (Win())
    wait ()
    disaster.Parent = workspace
end

1 answer

Log in to vote
0
Answered by
1N0body 206 Moderation Voter
8 years ago
Edited 8 years ago

Make them a function, example:

function humanoid()
return workspace:findFirstChild('Soldier')
end

It will check whenever you call it.

Or maybe make use of coroutines(+ loops) to update values in another thread(in another "routine").

http://wiki.roblox.com/index.php/Beginners_Guide_to_Coroutines

Ad

Answer this question