Hi all,
I am attempting to Connect a function whenever the Value
of a StringValue
changes.
Here is the section of the script that the error is coming from:
Summary
State.Value.Changed:Connect(function(old, new)
if StateTracker.State == "onRunning" then
print("Running check Good")
canDoubleJump = false
hasDoubleJumped = false
humanoid.JumpPower = oldPower
humanoid.PlatformStand = true
elseif StateTracker.State == "onFreeFall" then
print("Freefall Check Good")
wait(.1)
canDoubleJump = true
end
end)
A little bit of background as to why I’m not just using HumanoidStateType
:
Summary
I am using Gravity Controller which makes using HumanoidStateType basically impossible. The work around was included in Gravity Controller and basically makes a new HumanoidState tracking system, which is working fine.
I have a StringValue
that is allowing me to keep track of the current humanoid state of the player, which seems to be working fine.
I am trying to detect when this value changes, and to connect a function when that happens, allowing me to execute a double jump script.
This is the entire double jump script I currently have, it is kind of messy haha:
Summary
module = require(game:GetService("StarterPlayer").StarterCharacterScripts:WaitForChild("ModuleScript"))
local PLAYERS = module.PLAYERS
local GravityController = module.GravityController
local Controller = module.Controller
local StateTracker = module.StateTracker
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local State = character:WaitForChild("State")
local Animation = Instance.new("Animation")
Animation.AnimationId="rbxassetid://5930179191"
local FlapAN = humanoid:LoadAnimation(Animation)
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local jump_multi = 1.3
function onJumpRequest()
if not character or not humanoid or not character:IsDescendantOf(workspace) then
return
end
if canDoubleJump and not hasDoubleJumped then
print("DOUBLE JUMP CAN HAPPEN")
hasDoubleJumped = true
humanoid.JumpPower = oldPower * jump_multi
repeat StateTracker.State = "onJumping" until StateTracker.State == "onRunning"
end
end
local function characterAdded(new)
hasDoubleJumped = false
canDoubleJump = false
oldPower = humanoid.JumpPower
Animation = Instance.new("Animation")
Animation.AnimationId="rbxassetid://5918176410"
FlapAN = humanoid:LoadAnimation(Animation)
State.Value.Changed:Connect(function(old, new)
if StateTracker.State == "onRunning" then
print("Running check Good")
canDoubleJump = false
hasDoubleJumped = false
humanoid.JumpPower = oldPower
humanoid.PlatformStand = true
elseif StateTracker.State == "onFreeFall" then
print("Freefall Check Good")
wait(.1)
canDoubleJump = true
end
end)
end
if player.Character then
characterAdded(player.Character)
end
player.CharacterAdded:Connect(characterAdded)
UIS.JumpRequest:Connect(onJumpRequest)
while 1==1 do
print(humanoid:GetState(Enum.HumanoidStateType),"AND", StateTracker.State)
wait(.2)
end