Script either gives or removes your guns

So the guns I received (By class), either lets me receive one or two guns, or even one. It gives other people guns too.

-- // Variables

local player1 
local classofplr
local serverstorage = game.ServerStorage

-- // Function

local function loadchar(player1)
	player1.Character:Destroy()

	wait(1)

	local clone = game.ReplicatedStorage.LoadScreen:Clone()
	clone.Parent = player1.PlayerGui

	wait(2.5)

	clone:Destroy()

	player1:LoadCharacter()

end

-- // Remote Event Code

game.ReplicatedStorage.TGE:WaitForChild("TeamGearEvent").OnServerEvent:Connect(function(plr, class)
	player1 = plr
	if plr then
		classofplr = class
		class.Value = "RKR"
		loadchar(plr)
	end
end)

game.ReplicatedStorage.TGE:WaitForChild("TeamGearEvent2").OnServerEvent:Connect(function(plr, class)
	if plr then
		classofplr = class
		class.Value = "SHS"
		loadchar(plr)
	end
end)

game.ReplicatedStorage.TGE:WaitForChild("TeamGearEvent3").OnServerEvent:Connect(function(plr, class)
	if plr then
		classofplr = class
		class.Value = "OFI"
		loadchar(plr)
	end
end)

-- // Main Code

game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character)
		
		local backpack = player.Backpack or player1.Backpack
	
		if classofplr.Value == "RKR" then
			local musket = serverstorage:WaitForChild("Musket"):Clone()
			musket.Parent = backpack
		elseif classofplr.Value == "SHS" then
			local rifle = serverstorage:WaitForChild("Rifle"):Clone()
			rifle.Parent = backpack
			local sword = serverstorage:WaitForChild("Sword"):Clone()
			sword.Parent = backpack
		elseif classofplr.Value == "OFI" then
			local rifle = serverstorage:WaitForChild("Pistol"):Clone()
			rifle.Parent = backpack
			local sword = serverstorage:WaitForChild("Sword"):Clone()
			sword.Parent = backpack
		end
	end)
end)

What exactly is the problem with the script?

I would either receive random guns from classes selected by people who are using it. I’m not receiving my guns at all.

Try to put a StringValue under the player instead of the “classofplr” variable.
It looks like right now you’re using a global variable that is from everyone in the ServerScript.

1 Like