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

Why does this not work?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I'm not sure why its not working, i'm trying to make it so when you're close to distance it gives you a force shield and when you're not close to the distance it removes your force shield..

distance = 50


while true do
    for i,v in pairs(game.Players:GetChildren()) do
        human = v.Character:FindFirstChild("Torso")
        if human ~= nil and (script.Parent.Position - human.Position).magnitude <= distance then
            while (script.Parent.Position - human.Position).magnitude <= distance do
                script.Parent.BrickColor = BrickColor.new("Bright red")
                local Check = v.Character:FindFirstChild('ForceField')
                Check:Destroy()
                wait(0.04)
            end
            wait(0.04)
            local ForceField = Instance.new('ForceField', v.Character)
            script.Parent.BrickColor = BrickColor.new("Bright green")
        end
        wait(0.04)
    end
    wait(0.04)
end


0
you realize you have nested while loops, right... NoahWillCode 370 — 8y
0
Yes. UltraUnitMode 419 — 8y

Answer this question