instead of using this for every single action? this overlaps my other press E in a different script, how can i make it to all connect to one E button.
if (inputservice.TouchEnabled) then
local function onButtonPress()
print(“E PRESSED”)
Clicked = true
end
local mobilebutton = contextActionService:GetButton(“SprintButton”)
contextActionService:BindAction(“SprintButton”, onButtonPress, true, Enum.KeyCode.E)
contextActionService:SetPosition(“SprintButton”,UDim2.new(0.50,-25,0.20,-25))
contextActionService:SetImage(“SprintButton”,“http://www.roblox.com/asset/?id=3202644510”)
If you want two context actions to be executed by the same key, you can make the next function return Enum.ContextActionResult.Pass, and it will allow the subsequent function to run as well.
As for keeping everything on the same button, you would definitely have to change your script architecture to combine functions to a single button, since ContextActionService creates a new button for each action. As an example, you could bind the action so that it indexes a table that you can edit, like so:
local onBegin = {}
local onEnd = {}
local ActionE = {
[Enum.UserInputState.Begin] = onBegin,
[Enum.UserInputState.End] = onEnd
}
ContextActionService:BindAction("EButton", function(_, state, input)
if ActionE[state] then
for _, fn in pairs(ActionE[state]) do
coroutine.wrap(fn)(input)
end
end
end, true, Enum.KeyCode.E)
function onBegin.Sprint(input)
-- do the sprint
end)
function onBegin.PrintE(input)
print("E PRESSED")
end
-- etc
local hotkey = Enum.KeyCode.Tab
local hotkeyController = Enum.KeyCode.ButtonX
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key, gp)
if key.KeyCode == hotkey or key.KeyCode == hotkeyController then
if idk.Position == UDim2.new(0.5,0,-0.5,0) then
clickS:Play()
idk:TweenPosition(UDim2.new(0.5,0,0.5,0), "Out", "Bounce", 2)
wait(0.5)
epicblur.Enabled = not epicblur.Enabled
--character["Head"].Anchored = not character["Head"].Anchored
idk.Visible = not idk.Visible
elseif idk.Position == UDim2.new(0.5,0,0.5,0) then
clickS:Play()
--character["Head"].Anchored = false
idk:TweenPosition(UDim2.new(0.5,0,-0.5,0), "In", "Back", 1)
wait(0.5)
epicblur.Enabled = false
wait(0.5)
idk.Visible = false
end
end
end)