Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
OFF_S4LE 127
3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by
OFF_S4LE 127
3 years ago

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")

Ad

Answer this question