'Unable to cast token to token'

I want to check if the player holds down Ctrl and V at the same time but all I get is ‘Unable to cast token to token’ error
I only get the error when i press V not Ctrl or any other key

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed and input.KeyCode == Enum.KeyCode.V and UserInputService:IsKeyDown(Enum.ModifierKey.Ctrl) and UserInputService:GetFocusedTextBox()~= nil then
		wait(0.05)
		UserInputService:GetFocusedTextBox().Text = clipboard.Value
	elseif not gameProcessed and input.KeyCode == Enum.KeyCode.C and UserInputService:IsKeyDown(Enum.ModifierKey.Ctrl) and UserInputService:GetFocusedTextBox()~= nil then
		clipboard.Value = UserInputService:GetFocusedTextBox().Text
	end
end)

IsKeyDown only works with KeyCodes, not ModifierKeys. InputObjects, such as the thing returned by InputBegan have a function called IsModifierKeyDown, so I think you can use that

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed and input.KeyCode == Enum.KeyCode.V and input:IsModifierKeyDown(Enum.ModifierKey.Ctrl) and UserInputService:GetFocusedTextBox()~= nil then
		wait(0.05)
		UserInputService:GetFocusedTextBox().Text = clipboard.Value
	elseif not gameProcessed and input.KeyCode == Enum.KeyCode.C and input:IsModifierKeyDown(Enum.ModifierKey.Ctrl) and UserInputService:GetFocusedTextBox()~= nil then
		clipboard.Value = UserInputService:GetFocusedTextBox().Text
	end
end)

Although I’m not sure what is erroring, which line is the error on?

The error is on line 6. ill try the script you sent to me

1 Like

Any updates on the situation? Did my thing work or is it still erroring?

It works now! Thank you so much

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!