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

[Updated Again]Need help with a random generator script [?]

Asked by 8 years ago

I want to make a script that after you touch a block, it takes a random model from the lighting and puts it 56 blocks ahead of the model that the block you stepped on is in (I think I did this horribly wrong)

Obbys = {"Spin Tube","Ice Path","Laser1"}

function Cool()
local Obby = game.Lighting:FindFirstChild(Obbys[math.random(1,3)])
local Boo = Obby:Clone()
Boo.Parent = game.Workspace
Boo:MakeJoints()
Boo.Position = script.Parent.BaseArea.Position  + Vector3.new(56,0,0)
script:Destroy()
end

script.Parent.Touched:connect(Cool)

No errors works fine just I cant figure out how to move the models since they don't have a position property

2 answers

Log in to vote
0
Answered by 8 years ago

In line 7: That is the incorrect way of inserting value into a table.

InfO = {"Spin Tube","IcePath","Laser1"} 

items = {}
for i=1,#InfO do
local item = game.Lighting:findFirstChild(InfO[i])
if item ~= nil then
    table.insert(items, i,#InfO[i])
else
    print(InfO[i], " doesn't exist")
end
end

function chooseInfO()
return items[math.random(#items)]
end

function AddInfO()
local m = chooseInfO():Clone()--Clone() should alway have a Capital "C"
m.Parent = game.Workspace
m:MakeJoints()--Same for this.
m.Position = script.Parent.Parent.Position + Vector3.new(56,0,0)
end

script.Parent.Touched:connect(AddInfO)

Ad
Log in to vote
0
Answered by
Wutras 294 Moderation Voter
8 years ago

Well, the best way for you would be to use the function :SetPrimaryPartCFrame(0, 0, 0). You'd simply have to set the PrimaryPart before which could be done like this:

Obbys = {"Spin Tube","Ice Path","Laser1"}

function Cool()
local Obby = game.Lighting:FindFirstChild(Obbys[math.random(1,3)])
local Boo = Obby:Clone()
Boo.Parent = game.Workspace
Boo:MakeJoints()
Boo.PrimaryPart = math.random(1, #Boo:GetChildren())
Boo:SetPrimaryPartCFrame(script.Parent.BaseArea.CFrame+ CFrame.new(56,0,0)
)
script:Destroy()
end

script.Parent.Touched:connect(Cool)

Answer this question