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

I have 2 models I want to spawn at a random orientation and position but its only working for one?

Asked by 1 year ago
Edited 1 year ago

Pretty much I used basically the same code on both of the models just different variable names, but one model spawns at a random location (orientation still doesn't work) while the other one just spawns always at 0,0 why is this? Code:

if script.Parent.ClickDetector.MouseClick then --Random Dice Spawn

    Die1 = game.Workspace.GameParts.Dice.Die1

    Die2 = game.Workspace.GameParts.Dice.Die2

    Xaxis = math.random (0,50)

    Zaxis = math.random (0,50)

    Yaxis = math.random (200,250)

    Xaxis2 = math.random (0,50)

    Zaxis2 = math.random (0,50)

    Yaxis2 = math.random (200,250)

    Die1.PrimaryPart = Die1.Part

    Die2.PrimaryPart = Die2.Part2

    local Destination = CFrame.new(Xaxis,Yaxis,Zaxis)

    Die1:SetPrimaryPartCFrame(Destination)

    local Destination2 = CFrame.new(Xaxis2,Yaxis2,Zaxis2)

    Die2:SetPrimaryPartCFrame(Destination2)

    axis = math.random (0,90) 

    axis2 = math.random (0,90)

    axis3 = math.random (0,90)

    axis4 = math.random (0,90)

    axis5 = math.random (0,90)

    axis6 = math.random (0,90)

    Die1:PivotTo(CFrame.new(1,1,1) * CFrame.Angles(math.rad(axis),math.rad(axis2),math.rad(axis3)))

    Die1:PivotTo(CFrame.new(2,2,2) * CFrame.Angles(math.rad(axis4),math.rad(axis5),math.rad(axis6)))

I also welded all the parts together in each model, but I don't know how to do them all at once so I had to do it manually one by one.

0
Instead of using numbers for your NAMES use like DieA and PartA that could be the problem theking66hayday 841 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

ClickDetector.MouseClick is an event, not a boolean.

script.Parent.ClickDetector.MouseClick:Connect(function()
    local Die1 = workspace.GameParts.Dice.Die1
    local Die2 = workspace.GameParts.Dice.Die2

    local Xaxis = Random.new(os.time()):NextInteger(0,50)
    local Zaxis = Random.new(os.time()):NextInteger(0,50)
    local Yaxis = Random.new(os.time()):NextInteger(200,250)
    local Xaxis2 = Random.new(os.time()):NextInteger(0,50)
    local Zaxis2 = Random.new(os.time()):NextInteger(0,50)
    local Yaxis2 = Random.new(os.time()):NextInteger(200,250)

    local axis = Random.new(os.time()):NextInteger(0,90)
    local axis2 = Random.new(os.time()):NextInteger(0,90)
    local axis3 = Random.new(os.time()):NextInteger(0,90)
    local axis4 = Random.new(os.time()):NextInteger(0,90)
    local axis5 = Random.new(os.time()):NextInteger(0,90)
    local axis6 = Random.new(os.time()):NextInteger(0,90)

    local Destination = CFrame.new(Xaxis, Yaxis, Zaxis):ToWorldSpace(CFrame.Angles(math.rad(axis), math.rad(axis2), math.rad(axis3)))
    local Destination2 = CFrame.new(Xaxis2, Yaxis2, Zaxis2):ToWorldSpace(CFrame.Angles(math.rad(axis4), math.rad(axis5), math.rad(axis6)))

    Die1:PivotTo(Destination)
    Die2:PivotTo(Destination2)
end)
Ad

Answer this question