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

Why doesnt this script print a random value?

Asked by 4 years ago

I have recently been making where I need trash to appear in a specific area, however my script doesnt work. The output says that there is a error in line 13.

local TrashSpawnHere = game.Workspace.TrashSpawnHere

local function CreateTrash()
    local Trash = game.Workspace.TrashPart
    local TrashClone = Trash:Clone()
    TrashClone.Parent = game.Workspace

    local TrashSpawnHereSizeX = TrashSpawnHere.Size.X
    local XPostion = TrashSpawnHere.CFrame.X
    print(XPostion)
    local SecondValueX = XPostion - TrashSpawnHereSizeX
    print(SecondValueX)
    local XPositionRandom = math.random(XPostion,SecondValueX)

    local TrashSpawnHereSizeZ = TrashSpawnHere.Size.Z
    local ZPosition = TrashSpawnHere.CFrame.Z
    print(ZPosition)
    local SecondValueZ = ZPosition - TrashSpawnHere
    print(SecondValueZ)
    local ZPositionRandom = math.random(ZPosition,SecondValueZ)
end

while true do 
    CreateTrash()
    wait(2)
end
0
The numerical inputs within the math.radom function cannot be used for it's arethmetic operations Ziffixture 6913 — 4y
0
Is there a way I could rewrite the code, i have tried putting the actual numbers in instead of XPosition and SecondValueX, however it still returns an error. AndriusTheGreat 140 — 4y
0
Here´s the error : Workspace.TrashSpawn:13: bad argument #2 to 'random' (interval is empty) AndriusTheGreat 140 — 4y
0
I can't follow why didn't he just put numbers would be easier to use google to subtract that. voidofdeathfire 148 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

i BELieve the issue is because SecondValueZ is learned after you want it to print, the variable is placed after it which is likely the issue.

Ad

Answer this question