Sword fighting arena script giving infinite swords and other errors that don’t show

Hello, I am making a Sword Fighting arena but my script isnt working, I dont get any erros and i don’t know whats wrong please help!

Here is the Script :

2 Likes

well theres multiple issues with the script. first of all you are adding ontouched event everytime player joins (if multiple player joins then its gonna be a major issue/ as well as you check the gamepass id of a different player). secondly the during the arenaentered the code makes it so you get a sword regardless of the situation. lastly for arenaleave unless you have ALL POSSIBLE swords it doesnt remove any.
to fix this (by all means this is not optimal but works with what you have so far):

local mps = game:GetService("MarketplaceService")

local gamepass_bronze = 1092111
local gamepass_silver = 1092089
local gamepass_gold = 109209
local gamepass_plat = 1092094

local AF = game.Workspace.ArenaFolder -- We made a varible for the Arena Folder
local DF = AF.Doors -- We made a varible for the Doors Folder
 
local Possible_Swords = {
	['LinkedSword'] = true;
	['Windforce'] = true;
	['Ghostwalker'] = true;
	['Darkheart'] = true; 
	['Illumina'] = true;
}

--No need to clone this every single time someone steps on the brick..
local sw = game.ReplicatedStorage.LinkedSword -- Creating a varible of the sword and cloning it
local swB = game.ReplicatedStorage.Windforce
local swS = game.ReplicatedStorage.Ghostwalker
local swG = game.ReplicatedStorage.Darkheart
local swP = game.ReplicatedStorage.Illumina

local enabled = true; -- since it takes time for you to check for gamepasses

for _,v in pairs (DF:GetChildren()) do -- We are getting the children of the DF varible and assasing them to the V varible   
	if v.Name == "ArenaEnter" then -- Checking the V varible if its name is "ArenaEnter"
	    v.Touched:connect(function(Enter) -- We are checking to see if V was touched and making sure we spell touched right...
			if not enabled then return end;     
			enabled = false;       
			if Enter.Parent:FindFirstChild("Humanoid") then -- Checking to see if what touched V has a humanoid in its parent(Sounds weird)
	            local plr = game.Players:GetPlayerFromCharacter(Enter.Parent) -- Creating a varible for the player by using there character
	            local bp = plr.Backpack -- Creating a varible for the players backpack 
				for _, v in pairs(bp:GetChildren()) do
					if Possible_Swords[v.Name] then
						enabled = true;
						return --Since already have sword;
					end
				end
				local tool = Enter.Parent:FindFirstChildOfClass('Tool');
				if tool and Possible_Swords[tool.Name] then
					enabled = true;
					return --Equipping tool atm;
				end
				if mps:UserOwnsGamePassAsync(plr.UserId, gamepass_plat) then
					swP:clone().Parent = bp;
				elseif mps:UserOwnsGamePassAsync(plr.UserId, gamepass_gold) then
					swG:clone().Parent = bp;
				elseif mps:UserOwnsGamePassAsync(plr.UserId, gamepass_silver) then
					swS:clone().Parent = bp;
				elseif mps:UserOwnsGamePassAsync(plr.UserId, gamepass_bronze) then
					swB:clone().Parent = bp;
				else
					sw:clone().Parent = bp;
				end
			end
			enabled = true;
		end)
	elseif v.Name == "ArenaLeave" then -- Same as above execpt the name is ArenaLeave not ArenaEnter	         
		v.Touched:connect(function(Leave) -- We are checking to see if V was touched and making sure we spell touched right... Yep I wrote it again                    
			if Leave.Parent:FindFirstChild("Humanoid") then-- Checking to see if what touched V has a humanoid in its parent(still weird)               
				local plr = game.Players:GetPlayerFromCharacter(Leave.Parent) --Creating a varible for the player by using there character
	            local bp = plr.Backpack -- Creating a varible for the players backpack                
				for _, v in pairs(bp:GetChildren()) do
					if Possible_Swords[v.Name] then
						v:Destroy()
					end
				end
				for _, v in pairs(Leave.Parent:GetChildren()) do
					if Possible_Swords[v.Name] then
						v:Destroy()
					end
				end
			end -- 
		end) --
	end --
end	

Thank you! never done scripted anything like this before so thanks a lot!

Not saying this is necessary, but it’d be somewhat cool if you could keep the thread’s original content [Title + Issue], helps some people look at issues and try to solve them themselves, and can be archived for future reference to whoever has the same problem afterward.

This is completely unnecessary and doesn’t change anything except for what was mentioned.