Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

function generateMedKit(name,chords)
	local MedKits = game.ServerStorage.MedKits:FindFirstChild(name)                     
	local Cords = chords
	local randNum = math.random(1,#Cords)
	local chosenValue = Cords[randNum]
			print(chosenValue)
			MedKits.Parent = game.Workspace
			MedKits.Position = Vector3.new(chosenValue)
		end 
generateMedKit("Med1",{"5, 5, 5","10, 10, 10","20, 20, 20"})
generateMedKit("Med2",{"40, 40, 40","80, 80, 80","160, 180, 180"})
generateMedKit("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?

2 comments

0

Use tostring.

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.

1 answer

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

local function generateMedKit(name, chords)
    local MedKits = game:GetService("ServerStorage").MedKits:FindFirstChild(name)                     
    local Cords = chords
    local randNum = math.random(1, #Cords)
    local chosenValue = Cords[randNum]

    print(chosenValue)
    MedKits.Parent = game.Workspace
    MedKits.Position = Vector3.new(chosenValue)
end 
generateMedKit("Med1",{tonumber("5, 5, 5"), tonumber("10, 10, 10"), tonumber("20, 20, 20")})
generateMedKit("Med2",{tonumber("40, 40, 40"), tonumber("80, 80, 80"), tonumber("160, 180, 180")})
generateMedKit("Med3",{tonumber("360, 360, 360"), tonumber("720, 720, 720"), tonumber("1000,1000,1000")})

1 comment

0

When I use that code I get the error, "ServerScriptService.Script:4: bad argument #2 (interval is empty)"

This discussion is preserved as it was. New answers, comments, and votes are closed.