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

Context action service bind action local script wont work with my dashing local script?


Basically, I want to make my key-bind dash mobile friendly, because at the mo' it only activates when i press Q. I look up context action service and tried to bind my action to a function (Using the help of a YouTube tutorial) . But it doesn't work... Here's my code:


local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent") --Remote Event
local context = game:GetService("ContextActionService")
local ready = true

local function punch(inputObject, gameProcessed)
	UserInputService.InputBegan:Connect()
	if inputObject.KeyCode == Enum.KeyCode.F and ready then
		punchEvent:FireServer()
		ready = false
		wait(0.5)
		ready = true
	end
	
end


context:BindAction("FirePunchEvent", punch, true, "q")

Can anyone help me?

2 answers

✓ Accepted answer

because it is a function, you cant call it once you press "F" because you are not calling it outside of the function. Whenever you bind the action, you can list more keybinds for the function to happen.

Here is the fixed code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent") --Remote Event
local context = game:GetService("ContextActionService")
local ready = true

local function punch(inputObj, inputState, gameProcessed)
if inputState == Enum.UserInputState.Begin then
	if ready then
	ready = false
	punchEvent:FireServer() --args here
	wait(0.5)
	ready = true
end
end


context:BindAction("FirePunchEvent", punch, true, "q", "f")

2 comments

0

thx bro

0

np

math.randomseed(tick())

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = Instance.new("RemoteEvent", ReplicatedStorage)
punchEvent.Name = "PunchEvent"

local animations = {5311864256, 5311836453, 5311927306, 5311936839 } --Must be changed because the animations made by me won't work for other people than me. Make your own and insert the id's here, separated by commas.

local function onPunchFired(plr)
	local char = game.Workspace:FindFirstChild(plr.Name)
	local humanoid = char.Humanoid
	local animation = Instance.new("Animation")
	local picked = math.random(1, #animations)
	animation.AnimationId = "http://roblox.com/asset/?id="..animations[picked]
	local animTrack = humanoid:LoadAnimation(animation)
	animTrack:Play()
	local dmgScript = script.DmgScript:Clone()
	if picked == 1 then
		dmgScript.Parent = char.RightHand
	elseif picked == 2 then
		dmgScript.Parent = char.LeftHand
	
	elseif picked == 3 then
		dmgScript.Parent = char.RightFoot
		
	elseif picked == 4 then
		dmgScript.Parent = char.LeftFoot
end

	dmgScript.Disabled = false
	wait(0.4)
	dmgScript:Destroy()
end

punchEvent.OnServerEvent:Connect(onPunchFired)
---------------

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