I'm making a dodge mechanic for my game but for whatever reason when I press H dodgecount.Value gets set to 0 and dodgex doesn't change. I've gone through every other script and they can't be the problem since they add to dodgecount and don't subtract.
dodgex is a NumValue, dodgecount is an IntValue, and dodgeaddedvalue is an IntValue that is in another script to add to dodgecount.
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local dodgecount = game.StarterPlayer.StarterPlayerScripts.dodgecount
local debounce = false
local dodgeaddedvalue = game.StarterPlayer.StarterPlayerScripts.dodgeaddedvalue
local RunService = game:GetService("RunService")
inputservice = game:GetService("UserInputService")
dodgebar = script.Parent
dodgecount.Value = 5
inputservice.InputBegan:Connect(function(input, gameProccessedEvent)
local dodgex = game.StarterPlayer.StarterPlayerScripts.dodgex
dodgex.Value = 1
if dodgecount.Value > 0 then
if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Gamepad1 then
if gameProccessedEvent then return end
if input.KeyCode == Enum.KeyCode.H or input.KeyCode == Enum.KeyCode.ButtonB then
dodgeaddedvalue.Value = dodgeaddedvalue.Value + 1
dodgecount.Value = dodgecount.Value - 1
end
if debounce == false then
debounce = true
end
if dodgecount.Value == 5 then
dodgex.Value = 1
RunService.Heartbeat:Wait()
debounce = false
else
end
if dodgecount.Value == 4 then
dodgex.Value = 0.8
RunService.Heartbeat:Wait()
debounce = false
else
end
if dodgecount.Value == 3 then
dodgex.Value = 0.6
RunService.Heartbeat:Wait()
debounce = false
else
end
if dodgecount.Value == 2 then
dodgex.Value = 0.4
RunService.Heartbeat:Wait()
debounce = false
else
end
if dodgecount.Value == 1 then
dodgex.Value = 0.2
RunService.Heartbeat:Wait()
debounce = false
else
end
if dodgecount.Value == 0 then
dodgex.Value = 0
RunService.Heartbeat:Wait()
debounce = false
else
end
if dodgecount.Changed == true then
dodgebar:TweenSize(UDim2.new(dodgex, 0,1,0,"Out","Linear",1))
end
end
end
end)
dodgecount.Changed:Connect(function(countchanged)
local dodgex = dodgecount
if dodgecount.Value == 5 then
dodgex.Value = 1
else
end
if dodgecount.Value == 4 then
dodgex.Value = 0.8
else
end
if dodgecount.Value == 3 then
dodgex.Value = 0.6
else
end
if dodgecount.Value == 2 then
dodgex.Value = 0.4
else
end
if dodgecount.Value == 1 then
dodgex.Value = 0.2
else
end
if dodgecount.Value == 0 then
dodgex.Value = 0
else
end
dodgebar:TweenSize(UDim2.new(dodgex, 0,1,0,"In","Linear",1))
end)
Sorry if this is formatted badly since I'm relatively new to scripting.
