#How would I make this double jump script activate only when touching a certain object(doublejumppad)

60 messages · Page 1 of 1 (latest)

raven ibex
#

local MaxJumps = 2
local JumpCooldown = 0.2

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local NumberOfJumpsInARow = 0
local CanPlayerJump = false

Humanoid.StateChanged:connect(function(oldState, newState)

if Enum.HumanoidStateType.Landed == newState then
    NumberOfJumpsInARow = 0
    CanPlayerJump = false
elseif Enum.HumanoidStateType.Freefall == newState then
    task.wait(JumpCooldown)
    CanPlayerJump = true
elseif Enum.HumanoidStateType.Jumping == newState then
    CanPlayerJump = false
    NumberOfJumpsInARow += 1
end

end)

UserInputService.JumpRequest:Connect(function()

if CanPlayerJump and NumberOfJumpsInARow < MaxJumps then 
    Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end

end)

halcyon zinc
#

you can use getpartsbounds in box to figure out if the character is inside
or use part.Touched and part.TouchEnded

raven ibex
# halcyon zinc you can use getpartsbounds in box to figure out if the character is inside or us...

so I am actually not very experienced with scripting (as I should have mentioned) and I am sorry if I dont really understand how to do this. I found this code by searching in a tutorial 😭

so would I put these lines of code you gave me on the local script or the object? because the script is a local script and I am tryna figure out how to only activate this local script upon touch of this object

halcyon zinc
#

local script wouldn't work

#

put it inside the object

#

a script

raven ibex
#

ohhhh okay.

so put the exact script inside the object?

raven ibex
severe deltaBOT
#

studio** You are now Level 2! **studio

raven ibex
#

speed pad script btw

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.parent)

    local debounce = true
    
    if debounce == true then
        debounce = false
        
        player.Character.Humanoid.WalkSpeed = 65
        player.Character.Humanoid.JumpHeight = 15

        
        wait(0.5)
        debounce = true
    end
end

end)

halcyon zinc
#

what exactly do you mean by exact script

raven ibex
#

this function:

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.parent)

    local debounce = true

    if debounce == true then
        debounce = false
halcyon zinc
#
local touching = {}

local part = script.Parent

part.Touched:Connect(function(hit)
  if not hit.Parent:FindFirstChild("Humanoid") then return end
  local char = hit.Parent
  if touching[char] then return end
  touching[char] = true

  -- do code for when touching
end)

part.TouchEnded:Connect(function(hit)
  if not hit.Parent:FindFirstChild("Humanoid") then return end
  local char = hit.Parent
  if not touching[char] then return end
  touching[char] = nil

  -- do code when stopped touching
end)
#

i cooked up a script

#

it may not work first try but yk

raven ibex
#

thank you! lemme try... Should I put this before the double jump functions in the script?

halcyon zinc
#

do you need for me to explain how it works

#

i suggest replacing your script and editing parts

#

i suggest applying the activation of the script into the erm parts where it's needed

#

give me some time and i can cook up another

raven ibex
#

soo replace the script with this and edit the original script?

raven ibex
#

I honestly dont even really know what I am doing with this script LOL, this game has gotten me slightlyyy better at understanding how to explain the problems I am facing tho

halcyon zinc
#

ok so you can keep the double jump script

#
-- double jump (put inside characterscripts)
local MaxJumps = 2
local JumpCooldown = 0.2

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local NumberOfJumpsInARow = 0
local CanPlayerJump = false

Humanoid.StateChanged:connect(function(oldState, newState)

    if Enum.HumanoidStateType.Landed == newState then
        NumberOfJumpsInARow = 0
        CanPlayerJump = false
    elseif Enum.HumanoidStateType.Freefall == newState then
        task.wait(JumpCooldown)
        CanPlayerJump = true
    elseif Enum.HumanoidStateType.Jumping == newState then
        CanPlayerJump = false
        NumberOfJumpsInARow += 1
    end

end)

UserInputService.JumpRequest:Connect(function()
    if Character:GetAttribute("CanJump") == false then return end
    if CanPlayerJump and NumberOfJumpsInARow < MaxJumps then 
        Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    end

end)
-- block script
local touching = {}

local part = script.Parent

part.Touched:Connect(function(hit)
  if not hit.Parent:FindFirstChild("Humanoid") then return end
  local char = hit.Parent
  if touching[char] then return end
  touching[char] = true

  char:SetAttribute("CanJump", false)
end)

part.TouchEnded:Connect(function(hit)
  if not hit.Parent:FindFirstChild("Humanoid") then return end
  local char = hit.Parent
  if not touching[char] then return end
  touching[char] = nil
  
  char:SetAttribute("CanJump", false)
end)
#

what i did here is i added an attribute to the character which makes it (un)able to jump

#

able/unable

#

then the jump script checks the attribute to see if it can let the player do a double jump

#

it might not work, it might have errors

#

just saying

raven ibex
halcyon zinc
#

uh no

raven ibex
#

here lemme record a video

halcyon zinc
#

i edited the script

#

try the edited jump script

raven ibex
#

alr lemme try

halcyon zinc
#

you can try using getpartsbounds in box to check

#

i can't really say anything i'm playing right now, sorry

raven ibex
#

OOOOO okay so the jump works! BUT it stops when u hit the pad, how would I do the opposite effect?

raven ibex
halcyon zinc
raven ibex
#

lemme try and fix this myself because its working

#

YEAH

#

lemme do that

halcyon zinc
#

cange them places

#

swap i mean

raven ibex
#

should I also swap for the local script?

halcyon zinc
#

nah

#

swap the true and false in block script for reversed effect

raven ibex
#

alr

halcyon zinc
#

also it might sometimes not work because .touched is wonky

#

i suggest to use getpartsbounds in box

#

i can make one a bit later

raven ibex
#

okay so the double jump is working without touching the object still aaaaaa

halcyon zinc
#

yeah it's wonky

raven ibex
#

could I add you?

halcyon zinc
#

sure

raven ibex
#

coolio