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

How can I make a model randomly generator somewhere on the map?

Asked by 8 years ago
local iron = game.ReplicatedStorage.IronOre
local stone = game.ReplicatedStorage.StoneOre
local ores = 0
function RandomGen()
    while ores <= 20 do 
local newmodel = iron:Clone()
local newmodel2 = stone:Clone()
newmodel:MoveTo(Vector3.new(math.random(-247, 248), 2.52, math.random(-249, 249)))
ores = ores + 1
wait (.3)
    end
end

I am not very good with scripting but I'm trying to make it so that a ore will randomly spawn somewhere within the map.

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

You didn't call the function, so your code will never run. RandomGen().

Also, you never give the iron a parent, so it will just be nil. newmodel.Parent = workspace

Other than that, it looks right, although of course you never use the stone.

0
Is there a way I can make them not spawn on top of each other? jon162481 0 — 8y
0
Yes. Instead of using MoveTo, use SetPrimaryPartCFrame. Because CFrame allows objects to clip eachother. Just make sure you have the PrimaryPart set. Perci1 4988 — 8y
0
I am not quite sure how to do that... Sorry for being a noob. jon162481 0 — 8y
0
Just look up whatever you don't understand on the wiki, for example, http://wiki.roblox.com/index.php?title=API:Class/Model/SetPrimaryPartCFrame Perci1 4988 — 8y
View all comments (2 more)
0
That wiki page doesn't make any sense to me. jon162481 0 — 8y
0
You can ask a question about specifically what you don't understand Perci1 4988 — 8y
Ad

Answer this question