Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Instance not being created?

I have this simple black hole script that'll pull any brick in the PartStorage called "Rainbow Brick" towards it only if the Y value of it's position is less than 19.5. The output gives no error but each part called RainbowBrick doesn't have a BodyPosition child. Can anyone help me spot the problem?

local hole = script.Parent
local child = {}
for _, v in pairs(workspace.PartStorage:GetChildren()) do
    if v.Name == 'Rainbow Brick' then
        table.insert(child, v)
    end
end

for _, v in pairs(child) do
    if v.Anchored==false and v.Position.Y<=19.5 then
local relPos = hole.Position - child.Position
	local motivator = child:FindFirstChild("BlackHole Influence")
	if relPos.magnitude<=25 then
		if motivator == nil then
			motivator = Instance.new("BodyPosition")
			motivator.Parent = child
			motivator.Name = "BlackHole Influence"
		end
		motivator.position = hole.Position
		motivator.maxForce = 500
	end
    end
end

Thanks in advance

1 answer


local hole = script.Parent

local child = {}

for _, v in pairs(workspace.PartStorage:GetChildren()) do

    if v.Name == 'Rainbow Brick' then
         force=Instance.new("Body position",v) -- This help? Sorry I'm on my pad so this is a little hard.
force.Name="BlackHole Influence"
        table.insert(child, v)

    end

end

 

for _, v in pairs(child) do

    if v.Anchored==false and v.Position.Y<=19.5 then

local relPos = hole.Position - child.Position

    local motivator = child:FindFirstChild("BlackHole Influence")

    if relPos.magnitude<=25 then

        if motivator == nil then

            motivator = Instance.new("BodyPosition")

            motivator.Parent = child

            motivator.Name = "BlackHole Influence"

        end

        motivator.position = hole.Position

        motivator.maxForce = 500

    end

    end

end

1 comment

0

I see that you tried adding in the bodyposition right when the table detects it, but that sorta defeats the purpose of the second half of the script. But no sorry it didn't work still

This discussion is preserved as it was. New answers, comments, and votes are closed.