Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 5b03699

Browse files
garnold24Ben Tkacheff
authored andcommitted
CLI-3017 Mobile Jump Button Should Disappear If Jumping Disabled (#558)
* touch jump changes made MasterControl:GetHumanoid public, and used this in TouchJump to get the humanoid. When the JumpPower property changes, if it's less than 1, it hides the button, if its greater, it'll display it. * Added check for default disabled jump In the case the jump power is set before jump button initializes i added this check. * should work on respawn, and some other changes I reworked some of the code to make it more organized, buttons state changing should work on respawn, and made it so if the jump button gets disabled externally, it knows better than to reenable it without checking that first.
1 parent 88e890d commit 5b03699

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

PlayerScripts/PlayerScriptsPlace/StarterPlayer/StarterPlayerScripts/ControlScript/MasterControl.rbxmx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ local isSeated = false
3535
local myVehicleSeat = nil
3636
local moveValue = Vector3.new(0,0,0)
3737

38+
3839
--[[ Local Functions ]]--
39-
local function getHumanoid()
40+
function MasterControl:GetHumanoid()
4041
local character = LocalPlayer and LocalPlayer.Character
4142
if character then
4243
if CachedHumanoid and CachedHumanoid.Parent == character then
@@ -58,7 +59,7 @@ function MasterControl:Init()
5859

5960
local renderStepFunc = function()
6061
if LocalPlayer and LocalPlayer.Character then
61-
local humanoid = getHumanoid()
62+
local humanoid = self:GetHumanoid()
6263
if not humanoid then return end
6364

6465
if humanoid and not humanoid.PlatformStand and isJumping then
@@ -74,6 +75,8 @@ function MasterControl:Init()
7475
end
7576

7677
moveFunc(LocalPlayer, adjustedMoveValue, true)
78+
79+
7780
end
7881
end
7982

@@ -111,7 +114,7 @@ function MasterControl:SetIsJumping(jumping)
111114
end
112115

113116
function MasterControl:DoJump()
114-
local humanoid = getHumanoid()
117+
local humanoid = self:GetHumanoid()
115118
if humanoid then
116119
humanoid.Jump = true
117120
end

PlayerScripts/PlayerScriptsPlace/StarterPlayer/StarterPlayerScripts/ControlScript/MasterControl/TouchJump.rbxmx

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,53 @@ while not Players.LocalPlayer do
2626
wait()
2727
end
2828
local LocalPlayer = Players.LocalPlayer
29+
local Humanoid = MasterControl:GetHumanoid()
2930
local JumpButton = nil
3031
local OnInputEnded = nil -- defined in Create()
32+
local HumChangeConnection = nil
33+
local ExternallyEnabled = false --[[I don't think there's anything that disables jump from outside this script, but in case that ever happens,
34+
we don't want to re-enable it when jump power is changed]]
3135

3236
--[[ Constants ]]--
3337
local TOUCH_CONTROL_SHEET = "rbxasset://textures/ui/TouchControlsSheet.png"
3438

39+
--[[ Private Functions ]]--
40+
local function humanoidChanged(prop)
41+
if prop == "JumpPower" then
42+
if Humanoid.JumpPower == 0 then
43+
TouchJump:Disable()
44+
elseif Humanoid.JumpPower > 0 then
45+
TouchJump:Enable()
46+
end
47+
elseif prop == "Parent" then
48+
if not Humanoid.Parent then
49+
HumChangeConnection:disconnect()
50+
end
51+
end
52+
end
53+
54+
local function disableButton()
55+
JumpButton.Visible = false
56+
OnInputEnded()
57+
end
58+
59+
local function enableButton()
60+
if Humanoid and ExternallyEnabled then
61+
if Humanoid.JumpPower > 0 then
62+
JumpButton.Visible = true
63+
end
64+
end
65+
end
66+
3567
--[[ Public API ]]--
3668
function TouchJump:Enable()
37-
JumpButton.Visible = true
69+
ExternallyEnabled = true
70+
enableButton()
3871
end
3972

4073
function TouchJump:Disable()
41-
JumpButton.Visible = false
42-
OnInputEnded()
74+
ExternallyEnabled = false
75+
disableButton()
4376
end
4477

4578
function TouchJump:Create(parentFrame)
@@ -97,9 +130,25 @@ function TouchJump:Create(parentFrame)
97130
end
98131
end)
99132

133+
if Humanoid then
134+
HumChangeConnection = Humanoid.Changed:connect(humanoidChanged)
135+
end
100136
JumpButton.Parent = parentFrame
101137
end
102138

139+
LocalPlayer.CharacterAdded:connect(function(newCharacter)
140+
if HumChangeConnection then
141+
HumChangeConnection:disconnect()
142+
end
143+
-- rebind event to new Humanoid
144+
Humanoid = nil
145+
repeat
146+
Humanoid = MasterControl:GetHumanoid()
147+
wait()
148+
until Humanoid and Humanoid.Parent == newCharacter
149+
HumChangeConnection = Humanoid.Changed:connect(humanoidChanged)
150+
end)
151+
103152
return TouchJump
104153
]]></ProtectedString>
105154
</Properties>

0 commit comments

Comments
 (0)