Hi. I'm making a game that involves a tornado. I've been trying to implement different tornado strengths, by making each classification of tornado be able to pick up only certain types of materials. This is the script I have so far with nothing about that, and that works pretty well:
local hole = script.Parent -- Hole is kind of a code name for the tornado part (types easily).
local childList = {} -- Childlist is a list of debris that the tornado picks up.
local massConstant = 5.8
local mass = 32000 * massConstant
function checkObject(obj) -- Obj is the child model.
if (obj ~= hole) and (obj.className == "Part") then
if (obj.Anchored == false) then -- Will only make it debris if the part is not anchored.
table.insert(childList, 1, obj) -- Adds part to child list, making it debris.
end
elseif (obj.className == "Model") or (obj.className == "Hat") or (obj.className == "Tool") or (obj == workspace) then -- Just a precautionary measure.
local child = obj:GetChildren()
for x = 1, #child do
checkObject(child[x])
end
obj.ChildAdded:connect(checkObject)
end
end
checkObject(workspace)
print("Tornado Damage Script Loaded.")
local n = 0
while true do
if n < #childList then
n = n + 1
if n % 800 == 0 then
wait()
end
else
n = 1
wait()
end
local child = childList[n]
if (child ~= hole) and (child.className == "Part") and (child.Anchored == false) then
local relPos = hole.Position - child.Position
local motivator = child:FindFirstChild("BlackHole Influence") -- Motivator is what causes the part to go around the tornado.
if relPos.magnitude * 240 * massConstant < mass then
child:BreakJoints()
if (relPos.magnitude * 320 * massConstant < mass) and (child.Size.z + hole.Size.x > relPos.magnitude * 2 - 4) then
mass = mass + child:GetMass()
table.remove(childList, n)
n = n - 1
motivator:Remove() -- After a certain point, the debris will be spat out of the tornado, creating realistic tornado damage.
else
child.CanCollide = true
if motivator == nil then
motivator = Instance.new("BodyPosition")
motivator.Parent = child
motivator.Name = "BlackHole Influence"
end
motivator.position = hole.Position
motivator.maxForce = Vector3.new(1, 1, 1) * mass * child:GetMass() / (relPos.magnitude * massConstant)
end
elseif motivator ~= nil then
motivator:Remove()
end
end
end
What I had in mind at first was to insert an "and" statement into the "if/then" statement at line 10, as so:
if (obj.Anchored == false) and (obj.Material == "Pebble") then -- Will only make it debris if the part is not anchored.
table.insert(childList, 1, obj) -- Adds part to child list, making it debris.
end
"Pebble" is just an example for a material. I tried this and suddenly the tornado did absolutely no damage. What am I doing wrong?
