I am relatively new to using ContextActionService hence the reason why this code might be wrong. But currently what it does is when I press the button it starts the “local function Block” and starts from there, however I am not after this. I would like it so that when you press the button it runs the stuff from
“if inputState == Enum.UserInputState.Begin”
Previously the code used “input.KeyCode == Enum.KeyCode.T” where “inputState == Enum.UserInputState.Begin” but it wasn’t mobile compatible since you cant press the letter t on mobile.
What the script does is that it is part of 3 scripts. this specific script is designed so that when a part is clicked it will run the script and make your character pick up a part. Its designed so that when you press the mobile button it drops the part but it doesnt work. It worked when using input.KeyCode.T but isnt working when I try to switch it to inputState == Enum.UserInputState.Begin.
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local uis = game:GetService("UserInputService")
local hum = char:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(script.GrabBlockAnim)
local CanGrabBlock = true
local ContextActionService = game:GetService("ContextActionService")
local function Block(plr, block, actionName, inputState, inputObject)
if CanGrabBlock == true then
CanGrabBlock = false
anim:Play()
game.ReplicatedStorage.TakeBlock:FireServer(plr, block)
uis.InputBegan:Connect(function(input, GameprocessedEvent)
if inputState == Enum.UserInputState.Begin then
game.ReplicatedStorage.ThrowBlock:FireServer(plr, block)
anim:Stop()
wait(1)
CanGrabBlock = true
end
end)
end
end
game.ReplicatedStorage.ClientBlock.OnClientEvent:Connect(Block)
local mobilebutton = ContextActionService:BindAction("ThrowBlock" ,Block,true, Enum.KeyCode.T)
ContextActionService:SetPosition("Interact", UDim2.new(1, -70, 0, 10))