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

How do I make a randomizer with different levels of rarity and then teleport meshparts using it?

Asked by 6 years ago
Edited 6 years ago

Okay, I'm working on a mining game and I need some help with this script. It's a math.random randomizer with different rarity for each ore. I thought it would work, but nothing is cloning or teleporting. I'm still reasonably new to scripting and this might be completely wrong, so any help would be much appreciated. If you're still confused, I'll give you an example. If the math.random picks 32 then the script should clone a Diamond Ore to the position in the variable 'pos'. P.S. All "... Ore Models" are MeshParts if it helps.

orenumber = math.random(1,55)
pos = CFrame.new(Vector3.new(18, 1.248, 64))
copper = game.Workspace["Copper Ore Model"]
steel = game.Workspace["Steel Ore Model"]
gold = game.Workspace["Gold Ore Model"]
diamond = game.Workspace["Diamond Ore Model"]
amethyst = game.Workspace["Amethyst Ore Model"]
quartz = game.Workspace["Quartz Ore Model"]
blackopal = game.Workspace["Black Opal Ore Model"]
jadeite = game.Workspace["Jadeite Ore Model"]
musgravite = game.Workspace["Musgravite Ore Model"]
painite = game.Workspace["Painite Ore Model"]
if orenumber == 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 then
copper:Clone().CFrame = pos 
elseif orenumber == 11 or 12 or 13 or 14 or 15 or 16 or 17 or 18 or 19 then
steel:Clone().CFrame = pos  
elseif orenumber == 20 or 21 or 22 or 23 or 24 or 25 or 26 or 27 then
gold:Clone().CFrame = pos   
elseif orenumber == 29 or 30 or 31 or 32 or 33 or 34 then
diamond:Clone().CFrame = pos    
elseif orenumber == 35 or 36 or 37 or 38 or 39 or 40 then
amethyst:Clone().CFrame = pos   
elseif orenumber == 41 or 42 or 43 or 44 or 45 then
quartz:Clone().CFrame = pos
elseif orenumber == 46 or 47 or 48 or 49 then
blackopal:Clone().CFrame = pos  
elseif orenumber == 50 or 51 or 52 then
jadeite:Clone().CFrame = pos
elseif orenumber == 53 or 54 then
musgravite:Clone().CFrame = pos     
elseif orenumber == 55 then
painite:Clone().CFrame = pos
end
0
Your using CFrame and only including one parameter which is a Vector3. It isint ConvertToCFrame, it is CFrame.new. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

This does work, but since you did not set its parent, it is just lost in the heavens of your game, waiting to be parented. Also, CFrame needs 3 parameters, not 1. It is not ConvertToCFrame, so you should not have a vector3. Here is what your script should look like.

function ConvertToCFrame(pos)
    if typeof(pos) == 'Vector3' then
        return CFrame.new(pos.X, pos.Y, pos.Z)
    elseif typeof(pos) == 'CFrame' then
        return pos
    else
        return nil
    end
end

orenumber = math.random(1,55)
pos = ConvertToCFrame(Vector3.new(18, 1.248, 64))
copper = game.Workspace["Copper Ore Model"]
steel = game.Workspace["Steel Ore Model"]
gold = game.Workspace["Gold Ore Model"]
diamond = game.Workspace["Diamond Ore Model"]
amethyst = game.Workspace["Amethyst Ore Model"]
quartz = game.Workspace["Quartz Ore Model"]
blackopal = game.Workspace["Black Opal Ore Model"]
jadeite = game.Workspace["Jadeite Ore Model"]
musgravite = game.Workspace["Musgravite Ore Model"]
painite = game.Workspace["Painite Ore Model"]
if orenumber == 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 then
local c = copper:Clone()
c.CFrame = pos
c.Parent = workspace --DO NOT SET THE PARENT BEFORE YOU SET PROPERTIES.
--THIS CAUSES A BIG CHECK OF PROPERTIES ONCE PARENTED TO WORKSPACE.
elseif orenumber == 11 or 12 or 13 or 14 or 15 or 16 or 17 or 18 or 19 then
local c = steel:Clone()
c.CFrame = pos
c.Parent = workspace
elseif orenumber == 20 or 21 or 22 or 23 or 24 or 25 or 26 or 27 then
local c = gold:Clone()
c.CFrame = pos
c.Parent = workspace   
elseif orenumber == 29 or 30 or 31 or 32 or 33 or 34 then
local c = diamond:Clone()
c.CFrame = pos
c.Parent = workspace    
elseif orenumber == 35 or 36 or 37 or 38 or 39 or 40 then
local c = amethyst:Clone()
c.CFrame = pos
c.Parent = workspace  
elseif orenumber == 41 or 42 or 43 or 44 or 45 then
local c = quartz:Clone()
c.CFrame = pos
c.Parent = workspace
elseif orenumber == 46 or 47 or 48 or 49 then
local c = blackopal:Clone
c.CFrame = pos
c.Parent = workspace 
elseif orenumber == 50 or 51 or 52 then
local c = jadeite:Clone()
c.CFrame = pos
c.Parent = workspace
elseif orenumber == 53 or 54 then
local c = musgravite:Clone()
c.CFrame = pos
c.Parent = workspace 
elseif orenumber == 55 then
local c = painite:Clone()
c.CFrame = pos
c.Parent = workspace
end

Also, read my bio, otherwise I may not answer a future question of yours.

Hope this helps!

0
Major problem, it only clones the meshpart and not it's children, if there's any chance you could make it clone + tp it's children that would be much appreciated. I've tried myself but it's just not working. 360noscopehamcob 20 — 6y
0
Is the children connected to ANYthing of the meshpart or in a group? hiimgoodpack 2009 — 6y
Ad

Answer this question