Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to index upvalue 'UsingMove' (a boolean value) and Debounce issue [?]

#Goal:# My goal is to create a debounced move, this seems extremely simple but for some reason, it's not working. Currently, it works the first time I join but doesn't work anymore. It does give me an error though

#Script:# Module (ReplicatedStorage):

local MovesInfo = {
	Fireball = {
		Damage = 4;
		Cooldown = 5;
	};
};
return MovesInfo

LocalScript (StarterCharacterScripts):

local QDebounce = true

local Animations = {
	GreatFireBall = ReplicatedStorage.Animations['Great Fire Ball Animation [0.7]'];
}

local RE = {
	GreatFireBall = ReplicatedStorage.RemoteEvents.Moves['Great Fireball'];
}

local function FunctionLoadAndPlay(Humanoid, Move)
	if Move == 'Fireball' then
		local Animation = Humanoid:LoadAnimation(Animations.GreatFireBall)
		Animation:Play()
	end
end

UIS.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	local KeyCode = Input.KeyCode
	print(QDebounce)
	if QDebounce and KeyCode == Enum.KeyCode.Q and Char and UsingMove then
		local Move = Q.Value
		QDebounce = false
		print(QDebounce)
		UsingMove.Value = true
		RE.GreatFireBall:FireServer(Mouse.Hit, Move)
		FunctionLoadAndPlay(Humanoid, Move)
		wait(0.7)
		print(QDebounce)
		UsingMove = false
		wait(Moves.Fireball.Cooldown)
		QDebounce = true
		print(QDebounce)
	end
end)

Note that QDebounce is local QDebounce = true as a variable

#Prints:# true (x17) false false true true (x50)

Error: 17:00:45.501 - Workspace.BlackOrange3343_YT.Moves:48: attempt to index upvalue 'UsingMove' (a boolean value) 17:00:45.504 - Stack Begin 17:00:45.506 - Script 'Workspace.BlackOrange3343_YT.Moves', Line 48 17:00:45.508 - Stack End

which is if QDebounce and KeyCode == Enum.KeyCode.Q and Char and UsingMove then

I don't see why it works once but doesn't a second time.

How can I fix this? I Appreciate any helpful feedback thank you for reading.

1 comment

1 answer

✓ Accepted answer

You are receiving that error because of line 31. Here, you're trying to set 'UsingValue' to true, but not it's Value property.

Just change that line to:

UsingMove = false

However, in your error, it says that the error was on line 48. I'm assuming you edited part of the script out?

It is erroring in the if statement because you can't compare the object, you need to compare it's value.

Instead of doing if UsingValue then, do if UsingValue.Value then.

1 comment

0

Just looked through your script again, I think there may be multiple cases where you made this mistake.

This discussion is preserved as it was. New answers, comments, and votes are closed.