Why this isn't working?

  1. What do you want to achieve? Fix my script.

  2. What is the issue? My script was working, now isn’t working.

  3. What solutions have you tried so far? I tried to look at DevHub but i din’t found an solution.

Script:

	if hit.Parent:FindFirstChild("Humanoid") then
		script.Disabled = true
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local Equipped = player.Equipped
		local spawns = game.Workspace.Spawns
		local randSpawn = math.random(1, #spawns:GetChildren())
		local TeleSpawn = spawns:FindFirstChild(randSpawn)
		if TeleSpawn then
			local TelePos = TeleSpawn.Position 
			hit.Parent:moveTo(TelePos)
			local HandsFold = game:GetService("ServerStorage").Hands

			for i,v in pairs(HandsFold:GetChildren()) do
				local hand = v:FindFirstChild(Equipped.Value)
				if hand then
					hand = hand.Parent
					local ClonedHand = hand:Clone()
					ClonedHand.Parent = player.Backpack
				end
			end
			wait(0.25)
			script.Disabled = false
		else
			wait(0.25)
			script.Disabled = true
			return
		end
	end
end)

This error is showing up: Invalid argument #2 to random (interval is empty)

Whats wrong on this script?

Just move the characters model with Character:MoveTo(Vector3.new(-- put position here))

You need more than one item in the spawns folder.

theres 6 spawns points on the spawn folder

literally you set randSpawn to a number, try

local spanwsFolder = game.Workspace.Spawns
local spawns = spawnsFolder:GetChildren()

local randSpawn = spawns[math.random(#spawns)]
 -- gets instance from Spawns list based on number in [ ]

It din’t worked, the same error show up…

Invalid argument #1 to random (interval is empty)

ok, do

local spanwsFolder = game.Workspace.Spawns
local spawns = spawnsFolder:GetChildren()

local randSpawn = spawns[math.random(1, #spawns)]

and show me where the spawns folder is

The #1 error is gone, but the #2 error is back

then show where the spawns folder is
image
like this

i founded something, try this:

local spanwsFolder = game.Workspace.Spawns
local spawns = spawnsFolder:GetChildren()

local newArray = {}
for index,value in pairs(spawns) do -- edited
    table.insert(newArray, value["no matter"])
end

local randSpawn = spawns[math.random(1, #newArray)]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.