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

[SOLVED] I wanna learn how to fire my remote event through Context Action Service?

I made a local script that fire a remote event when you press left click, heres the script:

local debounce = false

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.Activated:Connect(function()
	if not debounce then
		debounce = true

		script.RemoteEvent:FireServer(mouse.Hit)
		local hum = player.Character.Humanoid

		for i = 1,15 do
			wait()
			hum.CameraOffset = Vector3.new(
				math.random(-1,1),
				math.random(-1,1),
				math.random(-1,1)
			)
		end
		hum.CameraOffset = Vector3.new(0,0,0)

		wait(2)
		debounce = false
	end
end)

Can someone edit this script using Context Action Service and explain how it works

1 answer

local debounce = false

function onKeyPress(actionName, userInputState, inputObject) if userInputState == Enum.UserInputState.Begin then print("X was pressed") local debounce = false

	local player = game.Players.LocalPlayer
	local mouse = player:GetMouse()

	script.Parent.Activated:Connect(function()
		if not debounce then
			debounce = true

			script.RemoteEvent:FireServer(mouse.Hit)
			local hum = player.Character.Humanoid

			for i = 1,15 do
				wait()
				hum.CameraOffset = Vector3.new(
					math.random(-1,1),
					math.random(-1,1),
					math.random(-1,1)
				)
			end
			hum.CameraOffset = Vector3.new(0,0,0)

			wait(2)
			debounce = false
		end
	end)
end

end

game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.X) game.ContextActionService:SetPosition("keyPressSpecialName", UDim2.new(.5,0,-.5,0)) game.ContextActionService:SetImage("keyPressSpecialName", "rbxassetid://73737626")

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