Hello!
So I am making a shop where you can buy items ad all that, and one of the items is DoubleJump. Whenever you buy it, it enables the jump script in StarterCharacterScripts. However, the double jump does not work when bought. I tried enabling it work when the player joined, and that worked.
Shop script:
local DoubleJumpScript = game.StarterPlayer.StarterCharacterScripts:WaitForChild("DoubleJumpScript")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local leaderstats = Player:WaitForChild("leaderstats")
local Coins = leaderstats:WaitForChild("Coins")
script.Parent.MouseButton1Click:Connect(function()
if Coins.Value == 1000 or Coins.Value >= 1000 then
Coins.Value -= 1000
DoubleJumpScript.Enabled = true
print("script enabled")
else
if Coins.Value <= 1000 then
print("not enough coins")
script.Parent.Parent.Parent.Parent.Error:Play()
end
end
end)
Jump script:
local MaxJumps = 2
local JumpCooldown = 0.2
----------------------------------------- Settings
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local NumJumps = 0
local canjump = false
Humanoid.StateChanged:Connect(function(oldstate, newstate)
if Enum.HumanoidStateType.Landed == newstate then
NumJumps = 0
canjump = false
elseif Enum.HumanoidStateType.Freefall == newstate then
wait(JumpCooldown)
canjump = true
elseif Enum.HumanoidStateType.Jumping == newstate then
canjump = false
NumJumps += 1
end
end)
UIS.JumpRequest:Connect(function()
if canjump and NumJumps < MaxJumps then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end)
If you think you know what went wrong, please let me know. Thank you and have a wonderful day! ![]()