local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local enemy = replicatedStorage:FindFirstChild("Enemy")
local dirt = replicatedStorage:FindFirstChild("Dirt")
local target = replicatedStorage:FindFirstChild("Target")
local greenPlate = game.Workspace.GreenPlate
local touchDebounce = false
local fight = false --> this means if there is already a fight happening
local function enemyChallenge(player)
if player then
for i = 1, 9 do
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
local rightFoot = character.RightFoot
local raycast = game.Workspace:Raycast(rightFoot.Position, -rightFoot.CFrame.UpVector * 100)
if raycast then
local newTarget = target:Clone()
newTarget.Position = raycast.Position
newTarget.Parent = game.Workspace
local newDirt = dirt:Clone()
newDirt.Position = raycast.Position
newDirt.Parent = game.Workspace
task.wait(0.9)
local newEnemy = enemy:Clone()
newEnemy:SetPrimaryPartCFrame(newDirt.CFrame - Vector3.new(0, 10, 0))
newEnemy.Parent = game.Workspace
task.wait(2)
newEnemy:Destroy()
newTarget:Destroy()
newDirt:Destroy()
end
task.wait(1)
end
end
local fight = false
end
greenPlate.Touched:Connect(function(PartThatTouched)
if fight == true then return end
if touchDebounce == true then return end
touchDebounce = true
if players:GetPlayerFromCharacter(PartThatTouched.Parent) then
local player = players:GetPlayerFromCharacter(PartThatTouched.Parent)
local inFight = player:FindFirstChild("InFight")
inFight.Value = true
fight = true
task.wait(.1)
enemyChallenge(player)
end
task.wait(2)
touchDebounce = false
end)
players.PlayerAdded:Connect(function(player)
local inFight = Instance.new("BoolValue")
inFight.Name = "InFight"
inFight.Parent = player
end)
I got help from a diffrent scripter and this is the entire script. task.wait did improve the consistency of the waiting time, however it is still not perfect. Someone suggested I try I runservice with thick() didnt use it before, but maybe you can help?