So, I’m making a Capture the Flag Game with a Red Team and a Blue Team. I wanted to make a script for switching between teams. I successfully made a Team Switch script for UI button but, I don’t know how to make a cooldown for it or how to kill the person so they respawn at the other team’s spawn. I tried multiple things, but I couldn’t find a way to do it.
The reason I want a cooldown and kill the person who is switching teams is because I don’t want players to abuse it, like getting free wins or kills by switching teams whenever they can.
local Players = game:GetService("Players")
local player = game.Players.Localplayer
local name = player.Name
script.Parent.MouseButton1Click:Connect(function()
game.name..TeamColor = BrickColor.new("Bright Blue")
player.Character.Humanoid.Health = 0
script.Parent.Parent.Visible = false
end)
Local script under Change to Red Team Button:
local Players = game:GetService("Players")
local player = game.Players.Localplayer
local name = player.Name
script.Parent.MouseButton1Click:Connect(function()
game.name..TeamColor = BrickColor.new("Bright Red")
player.Character.Humanoid.Health = 0
script.Parent.Parent.Visible = false
end)
Its probably something obvious, but don’t judge me because I’m a newbie.
local Players = game:GetService("Players")
local player = game.Players.Localplayer
local name = player.Name
local debounce = false
script.Parent.MouseButton1Click:Connect(function()
if debounce then
player.Character.Humanoid.Health = 0
return
end
debounce = true
player.TeamColor = BrickColor.new("Bright Red")
script.Parent.Parent.Visible = false
debounce = false
end)
local Players = game:GetService("Players")
local player = game.Players.Localplayer
local name = player.Name
local debounce = false
script.Parent.MouseButton1Click:Connect(function()
if debounce then
player.Character.Humanoid.Health = 0
return
end
debounce = true
player.TeamColor = BrickColor.new("Bright Blue")
script.Parent.Parent.Visible = false
debounce = false
end)
I’ve added a debounce, I’ve also fixed this line of code:
Incorrect. You’d have to use a RemoteEvent because if you try changing TeamColor, it’ll only change the TeamColor for the client and not the team itself in the server.
What do you mean “incorrect”? I didn’t state anything I was just showing that the client-server model warning doesn’t appear for one of the two team related player properties.
local Players = game:GetService("Players")
local player = game.Players.Localplayer
local name = player.Name
local debounce = false
script.Parent.MouseButton1Click:Connect(function()
if debounce then
player.Character.Humanoid.Health = 0
return
end
debounce = true
player.TeamColor = BrickColor.new("Bright Red")
script.Parent.Parent.Visible = false
task.wait(10)
debounce = false
end)
local Players = game:GetService("Players")
local player = game.Players.Localplayer
local name = player.Name
local debounce = false
script.Parent.MouseButton1Click:Connect(function()
if debounce then
player.Character.Humanoid.Health = 0
return
end
debounce = true
player.TeamColor = BrickColor.new("Bright Blue")
script.Parent.Parent.Visible = false
task.wait(10)
debounce = false
end)
The purpose of them was to add a delay, I forgot to do that but I’ve added them in the above.
game:GetService("Players").PlayerAdded:Connect(function(Player)
local CD = Instance.new("IntValue", Player)
CD.Name = "CD"
CD.Value = 0
while CD.Value > 0 do
CD.Value -= 1
wait()
end
local oldTeam = Player.TeamColor
Player:GetPropertyChangedSignal("TeamColor"):Connect(function()
if CD.Value > 0 then
Player.TeamColor = oldTeam
Player.Character:BreakJoints()
end
end)
end)
local UI = game.Players.LocalPlayer.PlayerGui.GUI.TextLabel -- wherever the label is
local Button = game.Players.LocalPlayer.PlayerGui.GUI.Button -- wherever the button is
local Player = game:GetService("Players")
Button.MouseButton1Down:Connect(function()
if Player.CD.Value > 0 then
UI.Text = "Please wait: ".. tostring(Player.CD.Value)
else
UI.Text = ""
end
end)