Error in script

no it’s being called only once from the MatchSystem script

When you change the maps to Workspace, what code do you use for it?

I clone children of Map and parent it to workspace

for i, v in pairs(MatchSystem.Map:GetChildren()) do
	v:Clone().Parent = game.Workspace.Map
end
--Modules--

--Variables--
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemotEvents"):FindFirstChild("RE1")
local a = 0 --check

--Module--
local OrbSystem = {}
OrbSystem.__index = OrbSystem

OrbSystem.Orbs = {}
OrbSystem.PlayersWithOrb = {}

function OrbSystem:SpawnOrbs(Mode, Bombs)
	a += 1 --check
	print(Mode.Name, Bombs, a)
	local Tiles = game.Workspace.Map.Tiles:GetChildren()
	for i, v in pairs(OrbSystem.Orbs) do
		local Tile = table.find(Tiles, v)
		if Tile then
			table.remove(Tiles, Tile)
		end
	end
	---for i, v in pairs(Bombs) do
	---	local Tile = table.find(Tiles, v)
	---	if Tile then
	---		table.remove(Tiles, Tile)
	---	end
	---end
	game.Workspace.Orbs:ClearAllChildren()
	
	for i, v in pairs(game:GetService("ServerStorage"):WaitForChild("Orbs"):GetChildren()) do
		local Min
		local Max
		if v.Name == "DoubleJumpOrb" then
			Min = Mode:GetAttribute("DoubleJumpOrbsMin")
			Max = Mode:GetAttribute("DoubleJumpOrbMax")
		elseif v.Name == "SwiftnessOrb" then
			Min = Mode:GetAttribute("SwiftnessOrbsMin")
			Max = Mode:GetAttribute("SwiftnessOrbsMax")
		elseif v.Name == "DashOrb" then
			Min = Mode:GetAttribute("DashOrbsMin")
			Max = Mode:GetAttribute("DashOrbsMax")
		elseif v.Name == "LowGravityOrb" then
			Min = Mode:GetAttribute("LowGravityOrbsMin")
			Max = Mode:GetAttribute("LowGravityOrbsMax")
		end
		if Max ~= 0 then
			for i = math.random(Min, Max), 1, -1 do
				if #Tiles >= 1 then
					local RndTile = Tiles[math.random(1, #Tiles)].Hitbox
					table.insert(OrbSystem.SpawnOrbs(), RndTile.Parent)
					local Clone = v:Clone()
					Clone.Parent = game.Workspace.Orbs
					Clone:MoveTo(RndTile.Position + Vector3.new(0, RndTile.Size.Y / 2 + Clone.Hitbox.Size.Y / 2 - 0.8, 0))
					for i, v in pairs(Clone:GetChildren()) do
						if v:IsA("Part") or v:IsA("MeshPart") then
							v.CanTouch = true
						end
					end
				end
			end
		end
	end
	
	for i, v in pairs(game.Workspace.Orbs:GetChildren()) do
		v.Hitbox.Touched:Connect(function(v1)
			if v1.Parent:FindFirstChild("Humanoid") ~= nil then
				if not table.find(OrbSystem.PlayersWithOrb, v1.Parent.Name) then -- and table.find(BombSystem.PlayersWithBomb, v1.Parent.Name)
					table.insert(OrbSystem.PlayersWithOrb, v1.Parent.Name)
					task.defer(function()
						task.wait(v:GetAttribute("AbilityTime") + 0.5)
						table.remove(OrbSystem.PlayersWithOrb, table.find(OrbSystem.PlayersWithOrb, v1.Parent.Name))
					end)
					if v.Name == "DoubleJumpOrb" then
						RemoteEvent:FireClient(game.Players:FindFirstChild(v1.Parent.Name), "Ability", v.Name, v:GetAttribute("AbilityTime"), v:GetAttribute("TimeToRefil"))
					elseif v.Name == "SwiftnessOrb" then
						RemoteEvent:FireClient(game.Players:FindFirstChild(v1.Parent.Name), "Ability", v.Name, v:GetAttribute("AbilityTime"), v:GetAttribute("SpeedMultiply"), v:GetAttribute("MultiplyWhenShpinting"))
					elseif v.Name == "DashOrb" then
						RemoteEvent:FireClient(game.Players:FindFirstChild(v1.Parent.Name), "Ability", v.Name, v:GetAttribute("AbilityTime"), v:GetAttribute("TimeToRefil"), v:GetAttribute("DashAnimation"))
					elseif v.Name == "LowGravityOrb" then
						RemoteEvent:FireClient(game.Players:FindFirstChild(v1.Parent.Name), "Ability", v.Name, v:GetAttribute("AbilityTime"), v:GetAttribute("LowGrav_FallAnim"))
					end
					for a, b in pairs(v:GetChildren()) do
						if b:IsA("Part") or b:IsA("MeshPart") then
							game:GetService("TweenService"):Create(b, TweenInfo.new(0.2, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0), {Size = Vector3.new(0, 0, 0)}):Play()
						end
					end
					task.wait(0.2)
					v:Destroy()
				end
			end
		end)
	end
end

return OrbSystem


so the function is called only once

while I was rechecking the whole code, I found out that I used table.insert(OrbSystem.SpawnOrbs(), RndTile.Parent instead of table.insert(OrbSystem.Orbs, RndTile.Parent which was causing the whole script to breakdown. Thankyou for helping me out tho.

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