So my function is suppose to print which turn it is. At first it is fine but when it loops the function the second time it prints it twice (ex. 1(x2)). I have tried debounce it would not work
Here is script 1
local RS = game:GetService("ReplicatedStorage")
local Turn = RS:WaitForChild("Turn")
local status = RS:WaitForChild("Status")
local times = 3
local function turn(num)
Turn.Value = num
end
while task.wait() do
if status.Value == "Fighting" then
task.wait(times)
Turn.Value = 1
task.wait(times)
turn(5)
task.wait(times)
turn(2)
task.wait(times)
turn(6)
task.wait(times)
turn(3)
task.wait(times)
turn(7)
task.wait(times)
turn(4)
task.wait(times)
turn(8)
task.wait(times)
turn(0)
status.Value = "Prepare"
RS:WaitForChild("timer").Value = 10
local Players = game:GetService("Players")
for i, v in pairs(Players:GetPlayers()) do
v.Power.Value += 1
end
else
end
end
Script 2
local RS = game:GetService("ReplicatedStorage")
local times = 3
local status = RS:WaitForChild("Status")
local Turn = RS:WaitForChild("Turn")
local db = false
local function fightPlr1(gridNum, TargetGridNum, dmg)
local plr1 = game.Workspace.Player1
local plr2 = game.Workspace.Player2
if Turn.Value == gridNum then
for i, v in pairs(plr2:GetChildren()) do
if v.Name == "GridPart" then
if v.GridNum.Value == TargetGridNum then
if v.Occupied.Value == true then
v:FindFirstChildWhichIsA("Model").Humanoid:TakeDamage(dmg)
else
end
end
end
end
end
end
local function fightPlr2(gridNum, TargetGridNum, dmg)
local plr1 = game.Workspace.Player1
local plr2 = game.Workspace.Player2
if Turn.Value == gridNum then
for i, v in pairs(plr1:GetChildren()) do
if v.GridNum.Value == TargetGridNum then
if v.Occupied.Value == true then
v:FindFirstChildWhichIsA("Model").Humanoid:TakeDamage(dmg)
else
end
end
end
end
end
status.Changed:Connect(function()
if status.Value == "Fighting" then
local plr1 = game.Workspace.Player1
local plr2 = game.Workspace.Player2
Turn.Changed:Connect(function()
print(Turn.Value)
for i, v in pairs(plr1:GetChildren()) do
if v:IsA("Part") then
if v.Name == "GridPart" then
if v.GridNum.Value == Turn.Value then
if v.Occupied.Value == true then
local figure = v:FindFirstChildWhichIsA("Model")
local anim = figure.Animations.Attack
local loadAnim = figure.Humanoid:LoadAnimation(anim)
loadAnim:Play()
fightPlr1(1,5,figure.Configuration.Damage.Value)
fightPlr1(2,6,figure.Configuration.Damage.Value)
fightPlr1(3,7,figure.Configuration.Damage.Value)
fightPlr1(4,8,figure.Configuration.Damage.Value)
end
end
end
end
end
for i, v in pairs(plr2:GetChildren()) do
if v:IsA("Part") then
if v.Name == "GridPart" then
if v.GridNum.Value == Turn.Value then
if v.Occupied.Value == true then
local figure = v:FindFirstChildWhichIsA("Model")
local anim = figure.Animations.Attack
local loadAnim = figure.Humanoid:LoadAnimation(anim)
loadAnim:Play()
fightPlr2(5,1,figure.Configuration.Damage.Value)
fightPlr2(6,2,figure.Configuration.Damage.Value)
fightPlr2(7,3,figure.Configuration.Damage.Value)
fightPlr2(8,4,figure.Configuration.Damage.Value)
end
end
end
end
end
end)
end
end)