I'm creating instances via a script yet for some reason roblox gives dodgecount the value that dodgex is supposed to get. Here's the script:

local localplayer = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local playerservice = game:GetService("Players")
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local debounce = false
local RunService = game:GetService("RunService")
inputservice = game:GetService("UserInputService")
dodgebar = script.Parent


local dodgexfind = localplayer.PlayerScripts:FindFirstChild("dodgex")
local dodgecfind = localplayer.PlayerScripts:FindFirstChild("dodgecount")


if not dodgexfind then
	local dodgexi = Instance.new("NumberValue")
	dodgexi.Parent = localplayer.PlayerScripts
	dodgexi.Name = "dodgex"
end

if not dodgecfind then
	local dodgec = Instance.new("IntValue")
	dodgec.Parent = localplayer.PlayerScripts
	dodgec.Name = "dodgecount"
	RunService.Heartbeat:Wait()
end

dodgecount = localplayer.PlayerScripts.dodgecount
dodgex = localplayer.PlayerScripts.dodgex


dodgecount.Value = 5

inputservice.InputBegan:Connect(function(input, gameProccessedEvent)	
	if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Gamepad1 then
		if gameProccessedEvent then return end
			if dodgecount.Value > 0 then		
				dodgecount.Value = dodgecount.Value - 1
					
			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 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) 

I put the dodgexfind and dodgecfind in there because it was creating two of each instance without them. As you can see, when dodgecount changes it's supposed to change dodgex. Whenever I press H dodgecount gets the value that dodgex is supposed to get and then it breaks. What is happening and how can it be fixed?

1 comment

0

Alright well after looking through it I realized I forgot to delete a test script. However now dodgecount goes to 0 instead of being subtracted by 1. Fixed one problem and another pops up.