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

How can I put Coordinates for a Vector3 in a list for a function?

Asked by 5 years ago
01function generateMedKit(name,chords)
02    local MedKits = game.ServerStorage.MedKits:FindFirstChild(name)                    
03    local Cords = chords
04    local randNum = math.random(1,#Cords)
05    local chosenValue = Cords[randNum]
06            print(chosenValue)
07            MedKits.Parent = game.Workspace
08            MedKits.Position = Vector3.new(chosenValue)
09        end
10generateMedKit("Med1",{"5, 5, 5","10, 10, 10","20, 20, 20"})
11generateMedKit("Med2",{"40, 40, 40","80, 80, 80","160, 180, 180"})
12generateMedKit("Med3",{"360, 360, 360","720, 720, 720","1000,1000,1000"})

I'm trying to randomly generate spawns for a medkit, but i think the coordinates in the argument are being read as strings so it doesn't work in the vector3.(). Or maybe I'm missing something else? How can I fix this?

0
Use tostring. LikeToScript 108 — 5y
0
Wdym tostring because it converts a number to a string and a vector3 returns a number not a string therefore it will yeild an error. JesseSong 3916 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You should use the tonumber() function. It converts a string into a number. Try this:

01local function generateMedKit(name, chords)
02    local MedKits = game:GetService("ServerStorage").MedKits:FindFirstChild(name)                    
03    local Cords = chords
04    local randNum = math.random(1, #Cords)
05    local chosenValue = Cords[randNum]
06 
07    print(chosenValue)
08    MedKits.Parent = game.Workspace
09    MedKits.Position = Vector3.new(chosenValue)
10end
11generateMedKit("Med1",{tonumber("5, 5, 5"), tonumber("10, 10, 10"), tonumber("20, 20, 20")})
12generateMedKit("Med2",{tonumber("40, 40, 40"), tonumber("80, 80, 80"), tonumber("160, 180, 180")})
13generateMedKit("Med3",{tonumber("360, 360, 360"), tonumber("720, 720, 720"), tonumber("1000,1000,1000")})
0
When I use that code I get the error, "ServerScriptService.Script:4: bad argument #2 (interval is empty)" ElectricZooo 55 — 5y
Ad

Answer this question