I'm trying to make a 2d game and my dodge script is in the works, my only problem is it's semi-working right now as I want to make it so when I'm off of the ground and I dodge, the debounce or wait is longer to use another consecutive dodge, so basically my script is doing what I just said BUT it's making me dodge twice in a short amount of time and then I dodge after a long time, this might not make any sense but I don't know how to explain it better. NOTE: When I touch the ground my dodge resets to the shorter debounce, here's a snippet of my script, this snippet is basically the same throughout the whole script, and don't blame me if the script if a bit messy, I have around 577 lines of code and I have yet to clean it up.
game.ReplicatedStorage.UpDodge.OnServerEvent:Connect(function(player)
local tweenService = game:GetService("TweenService")
local part = player.Character.HumanoidRootPart
if debounce == false then
debounce = true
counterparthappened = true
player.Character.LowerTorso.DodgeCircle.Trail.Enabled = true
player.Character.HumanoidRootPart.Anchored = true
local goal = {}
goal.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position + Vector3.new(0,12,0)) * CFrame.Angles(0, -1.5, 0)
local tweenInfo = TweenInfo.new(.2)
local tween = tweenService:Create(part, tweenInfo, goal)
tween:Play()
wait(.2)
player.Character.LowerTorso.DodgeCircle.Trail.Enabled = false
player.Character.HumanoidRootPart.Anchored = false
is1point5 = false
wait(Time)
is1point5 = true
if alreadydodged then
wait(Time2)
debounce = false
else alreadydodged = true
debounce = false
end
end
end)
game.ReplicatedStorage.UpDodge1.OnServerEvent:Connect(function(player)
if counterparthappened then
counterparthappened = false
local TweenService = game:GetService("TweenService")
local part = player.Character.LowerTorso.DodgeCircle
player.Character.LowerTorso.DodgeCircle.Transparency = 0
wait(.1)
local info = TweenInfo.new(
.1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals =
{
Transparency = 1;
Size = Vector3.new(10,10,10);
}
local tween = TweenService:Create(part,info,Goals)
tween:Play()
wait(.11)
player.Character.LowerTorso.DodgeCircle.Size = Vector3.new(8,8,8)
end
end)
Players.PlayerAdded:Connect(function(player)
local char = player.Character or player.CharacterAdded:wait()
coroutine.wrap(function()
while wait()do
local floor=char.Humanoid.FloorMaterial
if(tostring(floor)=="Enum.Material.Air")or(floor==nil)then
onair = true
else alreadydodged = false
print("on ground");
end
end
end)()
end)
there are a lot of random booleans here from when I was experimenting with the script, but basically what's happening in this script is when a remote event is fired from my local script (my local script fires the remote event when buttons are pressed) it enables and disables some stuff, blah blah, but then when I get to the ifalreadydodged part everything seems fine, I've been trying things for hours but I can't seem to get what's wrong, maybe this is a bit too much to ask. If you have any questions about my script or my other scripts reply please and I'll try to reply as well. NOTE: Time and Time2 = 1.5 (in total they add up to 3 which is how long the dodge debounce should take if I already dodged and I haven't touched the ground again)
