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

How can I get my duplication to invoke after changing Boolean value?

Asked by 4 years ago

Basically i'm trying to create a new part based on which existing part collides with my "Drill" part and after awhile i came up with this

local myPart = script.Parent
local otherPart = myPart.Touched
local stoneOre = game.ServerStorage["Stone_\"Ore\""]
local location = game.Workspace.BasicDrill.Dropper
local colliding = false
local printStonee = false

function onTouched(otherPart, colliding) ---- Finding out what part is touching the Drill
    if otherPart.Name == "Stone" then
        printStonee = true ---- Trying to invoke the while statement
    elseif otherPart.Name == "Coal" ---- Not important
        then
end
local function notTouched() ---- Trying to dissable the invoked statement when collision ends
    printStonee = false
end

myPart.Touched:Connect(onTouched) ---- To handle when the Drill is touched 
myPart.TouchEnded:Connect(notTouched) ----- To handle when the Drill ends its collison 

    while printStonee == true do ---- Continuously creating new parts when statement is true
        local newBlock = stoneOre:Clone()
        newBlock.Parent = location
        newBlock.Size = Vector3.new(1,1,1)
        end
    end



When I connect the "Stone" part to the "Drill" nothing happens no errors or anything. My script is located in the "Drill".The "Stone" part is in a folder in server storage but is copied into a folder in the Workspace. The new part or "StoneOre" is also located in Server storage and has no dedicated folder in the Workspace. The script is a server script. I've tried making it get invoked after setting printStonee to true.

1 answer

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

You cannot invoke a while statement. If the conditions are met when the script reads the loop, it will run, otherwise it won't.

You need the while loop to always run, and put your if statement within it:

while true do -- will run as long as the script runs
    if printStonee then
        local newBlock = stoneOre:Clone()
        newBlock.Parent = location
        newBlock.Size = Vector3.new(1,1,1)
    end
    game:GetService("RunService").Heartbeat:Wait() -- delay iterations to avoid crash
end
Ad

Answer this question