I got an error and it seems like my way of randomising the item location is wrong.Can anybody tell me what is wrong with it?It will be a really good help.The error says:"Workspace.Part.Script:6:wrong number or arguments."The part is in Workspace,the part being with a script inside it.Also i ran the test in run mode in Roblox Studio and the print doesnt seem to work either,if you dont know what line to look at you should look at line 6.Sorry that the script looks bad in the website.I'm new to it.
local brick = script.Parent
brick.CanCollide = false brick.Parent = game.Workspace
local key = math.random(1,2,3,4) if key == 1 then brick.Position = Vector3.new(-116.75,18.859,387.5) print("first") elseif key == 2 then brick.Position = Vector3.new(-156.75,18.859,389.5) print("second") elseif key == 3 then brick.Position = Vector3.new(-135.25,18.859,368.5) print("third") elseif key == 4 then brick.Position = Vector3.new(-135.75, 18.859, 387.5) print("fourth") end
Hello, SitaruDaniel!
local brick = script.Parent brick.CanCollide = false brick.Parent = game.Workspace local key = math.random(1,4) -- Arguments of math.random: min, max if key == 1 then brick.Position = Vector3.new(-116.75,18.859,387.5) print("first") elseif key == 2 then brick.Position = Vector3.new(-156.75,18.859,389.5) print("second") elseif key == 3 then brick.Position = Vector3.new(-135.25,18.859,368.5) print("third") elseif key == 4 then brick.Position = Vector3.new(-135.75, 18.859, 387.5) print("fourth") end
Hi Sitaru, There is an issue with your script, and also an enhancement that can be made to your script. So, let's get right into it!
local vectors = { -- Contains all of your vectors Vector3.new(-116.75,18.859,387.5), Vector3.new(-156.75,18.859,389.5), Vector3.new(-135.25,18.859,368.5), Vector3.new(-135.75, 18.859, 387.5), } local key = math.random(1, 4) brick.Position = vectors[key] -- Accesses the vector in the table, using the key as an index.
Thanks,
Best regards,
IdealstDeveloper