When you click a button, you get a sword, but when you click the other button it removes the sword.
But if I want to get the sword again, it gives me another one.
local part = workspace.VillainPart
local click = part.ClickDetector
local teams = game.Teams
local villain = false
click.MouseClick:Connect(function(player)
local function swap()
player.Team = teams.Villain or teams:FindFirstChild("Villain")
local sword = game.ServerStorage.Sword:Clone()
sword.Parent = player.Backpack
end
if teams:FindFirstChild("Villain") then
swap()
else
villain = false
end
if villain == false then
local villainteam = Instance.new("Team")
villainteam.Parent = teams
villainteam.Name = "Villain"
villainteam.TeamColor = BrickColor.new("Cocoa")
swap()
end
end)
local part = workspace.CitizenPart
local click = part.ClickDetector
local teams = game.Teams
local civilian
click.MouseClick:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local function swap()
player.Team = teams.Civilian or teams:FindFirstChild("Civilian")
local sword = player.Backpack:FindFirstChild("Sword") or character:FindFirstChild("Sword")
if sword then
sword:Destroy()
end
end
if teams:FindFirstChild("Civilian") then
swap()
else
civilian = false
end
if civilian == false then
local civilianteam = Instance.new("Team")
civilianteam.Parent = teams
civilianteam.TeamColor = BrickColor.new("Pastel brown")
civilianteam.Name = "Civilian"
civilian = true
swap()
end
end)