Every time I try to run this script I get a error saying:
Workspace.Script:16: bad argument #2 to 'random' (number expected, got nil)
Here is the output:
10
10
10
Workspace.Script:16: bad argument #2 to 'random' (number expected, got nil)
Script 'Workspace.Script', Line 16 - global SpawnRandomPostion
Script 'Workspace.Script', Line 26
Stack End
Script:
--[[Purpose of script:
This script is suppose to spawn a part in a random spot using the baseplate's position--]]
------------------------Vairbles-----------------------
BaseplatePositions= {
BaseplateX = game.Workspace.BasePlate.Position.X,
BaseplateY= game.Workspace.BasePlate.Position.Y,
BaseplateZ = game.Workspace.BasePlate.Position.Z
}
for i,v in pairs (BaseplatePositions) do--Check
print(v)
end
------------------------Function------------------------
function SpawnRandomPostion(X,Y,Z)
local Cordinates ={
PartX = math.random(0,X),
PartY = math.random(0,Y),
PartZ = math.random(0,Z)
}
for k,o in pairs (Cordinates) do--Check
print(o)
end
return Vector3.new(Cordinates[1],Cordinates[2],Cordinates[3])
end
---------------------------------------------------------
Part = Instance.new("Part",game.workspace)
RPosition = SpawnRandomPostion(BaseplatePositions[1],BaseplatePositions[2],BaseplatePositions[3])
Part.Position = RPosition
Part.Anchored = true
print(RPosition)--Check
Why did I get this error and how do I fix it?
If you manged to fix it show me how you did it,thank you.
