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

Help binding actions for mobile?

Hi, I'm trying to make my game more mobile compatible. Can someone help with me binding a skill functions? Thanks.

local cas = game:GetService("ContextActionService")
local plr = game.Players.LocalPlayer
local char = plr.Character
repeat wait() until char.Humanoid
local hum = char.Humanoid
repeat wait() until plr.Skills
local skills = plr.Skills
local speed = skills.Speed
local invis = skills.Invisibility
local cooldown = false
function useskillmobile()
  if cooldown == false then
	if speed == true then
		hum.WalkSpeed = 24
		cooldown = true
		wait(5)
		cooldown = false
		hum.WalkSpeed = 16
	elseif invis == true then
		char["Left Arm"].Transparency = 1
		char["Right Arm"].Transparency = 1
		char["Left Leg"].Transparency = 1
		char["Right Leg"].Transparency = 1
		char["Torso"].Transparency = 1
		char["Head"].Transparency = 1
		cooldown = true
		wait(5)
		char["Left Arm"].Transparency = 0
		char["Right Arm"].Transparency = 0
		char["Left Leg"].Transparency = 0
		char["Right Leg"].Transparency = 0
		char["Torso"].Transparency = 0
		char["Head"].Transparency = 0
		cooldown = false
		end
	end
end
cas:BindAction("Use Skill", useskillmobile, true, "x")

1 answer

✓ Accepted answer

Your general usage of ContextActionService isn't the issue, there are a couple of errors within your function that are causing the issue, I have labelled them in my quick re-write as I debugged it.

local CAS 		=	game:GetService("ContextActionService");
local plr 		=	game:GetService("Players").LocalPlayer;
local char 		=	plr.Character or plr.CharacterAdded:Wait();
local hum 		=	char:WaitForChild("Humanoid");
local skills 	=	plr:WaitForChild("Skills");
local speed 	=	skills.Speed;
local invis 	=	skills.Invisibility;

local cooldown 	=	false;

function useSkillMobile()
	if (not cooldown) then
		if (speed.Value == true) then -- We need to reference .Value when referring to a BoolValue object;
			hum.WalkSpeed 	=	24;
			cooldown 		=	true;
			wait(5);
			cooldown 		=	false;
			hum.WalkSpeed 	=	16;
		end

		if (invis.Value == true) then -- We need to reference .Value when referring to a BoolValue object;
			char["Left Arm"].Transparency 		= 	1;
        	char["Right Arm"].Transparency 		= 	1;
        	char["Left Leg"].Transparency 		= 	1;
        	char["Right Leg"].Transparency 		= 	1;
        	char["Torso"].Transparency 			= 	1;
        	char["Head"].Transparency 			= 	1;
        	cooldown 							= 	true;
        	wait(5);
        	char["Left Arm"].Transparency 		= 	0;
        	char["Right Arm"].Transparency 		= 	0;
        	char["Left Leg"].Transparency 		= 	0;
        	char["Right Leg"].Transparency 		= 	0;
        	char["Torso"].Transparency 			= 	0;
        	char["Head"].Transparency 			= 	0;
        	cooldown 							= 	false;
        end
    end
end

CAS:BindAction("Use Skill", useSkillMobile, true, "x");

2 comments

1

Thank you. I actually really forget sometimes to put .Value at some of them. Thanks.

0

No problem.

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