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

Shows error: "Unable to cast token to token" when using contextactionservice?

I have two functions (to gather movement for left and right) but whenever i try to run them. it says: "ContextActionService: Unexpected error while invoking callback: Unable to cast token to token"

LocalScript:

-- Functions for movement
local function onChoseRight(actionName, inputState)
	if UserInputService:IsKeyDown(inputState) then
		chosevalue+=1		
	end
end
local function onChoseLeft(actionName, inputState)
	if UserInputService:IsKeyDown(inputState) then 
		chosevalue-=1
	end
end


-- Main Problem:
ContextActionService:BindAction("Left", onChoseLeft, true, "L", Enum.KeyCode.Left)
ContextActionService:BindAction("Right", onChoseRight, true, "R", Enum.KeyCode.Right)

1 answer

Solved it myself, just had to replace the userinputservice thing:

	local function onChoseRight(actionName, inputState)
		if inputState == Enum.UserInputState.Begin then
			chosevalue+=1
			print(chosevalue)
		end
	end
	local function onChoseLeft(actionName, inputState)
		if inputState == Enum.UserInputState.Begin then
			chosevalue-=1
			print(chosevalue)
		end
	end
	

1 comment

0

Good Job!

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