#Did I explain this code right?

1 messages · Page 1 of 1 (latest)

hasty wyvern
#

local UserInputService = game:GetService("UserInputService") --gets userinput
local char = script.Parent --gets character
local hum = char:WaitForChild("Humanoid") --gets humanoid in character

local prevjump = tick() --Sets the prev jump time to the tick when prevjump is used
local IsDoubleJumping = false --The player has not double jumped

hum.StateChanged:Connect(function(oldState,newState) --If the humanoid changed its state then
if newState == Enum.HumanoidStateType.Landed then --if the player has just landed then player can't double jump
IsDoubleJumping = false
elseif newState == Enum.HumanoidStateType.Jumping then --if the player has jumped then
prevjump = tick() --sets prevjump to this tick
end
end)
UserInputService.InputBegan:Connect(function(input) --when a player presses a key
if input.KeyCode == Enum.KeyCode.Space then --if the keycode is space then
if tick() - prevjump <= 0.25 then --if the current time - prevjump time is less than or = to 0.25 meaning its been less than 0.25 seconds since hes jumped then
if hum:GetState() == Enum.HumanoidStateType.Freefall and not IsDoubleJumping then --if the player is freefalling and he hasn't double jumped yet then
IsDoubleJumping = true --it sets doublejump to true meaning he just double jumped
hum:ChangeState(Enum.HumanoidStateType.Jumping) --Changes the state of the humanoid to jumping again
end
end
end
end)

With the comments, did I explain it well? Also, is it just me? I think I am very stupid because when I try and make code myself its rlly bad and bugs a lot but when I check someone elses code and it looks great I understand it so well and I am like "Why didn't I think of that?" I wish I could combine everything I know into a non-buggy code and I started coding like 2 weeks ago, and I still can barely form code with CODE I ALREADY KNOW! is this normal for beginners? If not, how can I help this?

untold kiln
untold kiln
#

pretty sure you need to use some sort of body velocity to make the player double jump

hasty wyvern
#

No it works

coral prairie
untold kiln
#

fr?

hasty wyvern
#

ye

untold kiln
#

oh wow yeah it does

#

that cool

#

didnt know it did that

hasty wyvern
hasty wyvern
#

on why tf I can't do shit like this on my own when I know it

coral prairie
hasty wyvern
#

and when I look at other scripts im like "oh why didn't I think of that"

untold kiln
#

i mean u did it just fine

hasty wyvern
#

I followed a tutorial

#

I just wanna know if I explained it well

#

cause the tutorial showed me hum states and properties

#

then used them to make a double jump

untold kiln
#

I see

#

well what is your knowledge so far

#

what do you know

hasty wyvern
untold kiln
hasty wyvern
#
local char = script.Parent --gets character
local hum = char:WaitForChild("Humanoid") --gets humanoid in character

local prevjump = tick() --Sets the prev jump time to the tick when prevjump is used
local IsDoubleJumping = false --The player has not double jumped

hum.StateChanged:Connect(function(oldState,newState) --If the humanoid changed its state then
    if newState == Enum.HumanoidStateType.Landed then --if the player has just landed then player can't double jump
        IsDoubleJumping = false
    elseif newState == Enum.HumanoidStateType.Jumping then --if the player has jumped then
        prevjump = tick() --sets prevjump to this tick 
    end
end)
UserInputService.InputBegan:Connect(function(input) --when a player presses a key
    if input.KeyCode == Enum.KeyCode.Space then --if the keycode is space then
        if tick() - prevjump <= 0.25 then --if the current time - prevjump time is less than or = to 0.25 meaning its been less than 0.25 seconds since hes jumped then
            if hum:GetState() == Enum.HumanoidStateType.Freefall and not IsDoubleJumping then --if the player is freefalling and he hasn't double jumped yet then
                IsDoubleJumping = true --it sets doublejump to true meaning he just double jumped
                hum:ChangeState(Enum.HumanoidStateType.Jumping) --Changes the state of the humanoid to jumping again
            end
        end
    end
end)````
untold kiln
#
local UserInputService = game:GetService("UserInputService") --gets userinput
local char = script.Parent --gets character
local hum = char:WaitForChild("Humanoid") --gets humanoid in character

local prevjump = tick() --Sets the prev jump time to the tick when prevjump is used
local IsDoubleJumping = false --The player has not double jumped

hum.StateChanged:Connect(function(oldState,newState) --If the humanoid changed its state then
    if newState == Enum.HumanoidStateType.Landed then --if the player has just landed then player can't double jump
        IsDoubleJumping = false
    elseif newState == Enum.HumanoidStateType.Jumping then --if the player has jumped then
        prevjump = tick() --sets prevjump to this tick 
    end
end)
UserInputService.InputBegan:Connect(function(input) --when a player presses a key
    if input.KeyCode == Enum.KeyCode.Space then --if the keycode is space then
        if tick() - prevjump <= 0.25 then --if the current time - prevjump time is less than or = to 0.25 meaning its been less than 0.25 seconds since hes jumped then
            if hum:GetState() == Enum.HumanoidStateType.Freefall and not IsDoubleJumping then --if the player is freefalling and he hasn't double jumped yet then
                IsDoubleJumping = true --it sets doublejump to true meaning he just double jumped
                hum:ChangeState(Enum.HumanoidStateType.Jumping) --Changes the state of the humanoid to jumping again
            end
        end
    end
end)```
coral prairie
hasty wyvern
#
local char = script.Parent --gets character
local hum = char:WaitForChild("Humanoid") --gets humanoid in character

local prevjump = tick() --Sets the prev jump time to the tick when prevjump is used
local IsDoubleJumping = false --The player has not double jumped

hum.StateChanged:Connect(function(oldState,newState) --If the humanoid changed its state then
    if newState == Enum.HumanoidStateType.Landed then --if the player has just landed then player can't double jump
        IsDoubleJumping = false
    elseif newState == Enum.HumanoidStateType.Jumping then --if the player has jumped then
        prevjump = tick() --sets prevjump to this tick 
    end
end)
UserInputService.InputBegan:Connect(function(input) --when a player presses a key
    if input.KeyCode == Enum.KeyCode.Space then --if the keycode is space then
        if tick() - prevjump <= 0.25 then --if the current time - prevjump time is less than or = to 0.25 meaning its been less than 0.25 seconds since hes jumped then
            if hum:GetState() == Enum.HumanoidStateType.Freefall and not IsDoubleJumping then --if the player is freefalling and he hasn't double jumped yet then
                IsDoubleJumping = true --it sets doublejump to true meaning he just double jumped
                hum:ChangeState(Enum.HumanoidStateType.Jumping) --Changes the state of the humanoid to jumping again
            end
        end
    end
end)```
untold kiln
#

LOL

#
local UserInputService = game:GetService("UserInputService") --gets userinput
local char = script.Parent --gets character
local hum = char:WaitForChild("Humanoid") --gets humanoid in character

local prevjump = tick() --Sets the prev jump time to the tick when prevjump is used
local IsDoubleJumping = false --The player has not double jumped

hum.StateChanged:Connect(function(oldState,newState) --If the humanoid changed its state then
    if newState == Enum.HumanoidStateType.Landed then --if the player has just landed then player can't double jump
        IsDoubleJumping = false
    elseif newState == Enum.HumanoidStateType.Jumping then --if the player has jumped then
        prevjump = tick() --sets prevjump to this tick 
    end
end)
UserInputService.InputBegan:Connect(function(input) --when a player presses a key
    if input.KeyCode == Enum.KeyCode.Space then --if the keycode is space then
        if tick() - prevjump <= 0.25 then --if the current time - prevjump time is less than or = to 0.25 meaning its been less than 0.25 seconds since hes jumped then
            if hum:GetState() == Enum.HumanoidStateType.Freefall and not IsDoubleJumping then --if the player is freefalling and he hasn't double jumped yet then
                IsDoubleJumping = true --it sets doublejump to true meaning he just double jumped
                hum:ChangeState(Enum.HumanoidStateType.Jumping) --Changes the state of the humanoid to jumping again
            end
        end
    end
end)```
coral prairie
#

can we stop

#

flooding

untold kiln
#

bruh

untold kiln
untold kiln
#

i dont think you should use tutorials for this stuff tho

hasty wyvern
#

Learn how to implement humanoids in your scripts through features such as humanoid states, properties, and methods. This video includes Walkspeed, Jumppower, Health, Sit, MoveTo, TakeDamage, and a double jump system implementation!

PATREON🎁
Get Access To My Scripts + More Perks By Becoming a Patreon Member! 👇
https://www.patreon.com/Brawl...

▶ Play video
untold kiln
#

like variables, functions

hasty wyvern
#
local UserInputService = game:GetService("UserInputService") --gets userinput
local char = script.Parent --gets character
local hum = char:WaitForChild("Humanoid") --gets humanoid in character

local prevjump = tick() --Sets the prev jump time to the tick when prevjump is used
local IsDoubleJumping = false --The player has not double jumped

hum.StateChanged:Connect(function(oldState,newState) --If the humanoid changed its state then
    if newState == Enum.HumanoidStateType.Landed then --if the player has just landed then player can't double jump
        IsDoubleJumping = false
    elseif newState == Enum.HumanoidStateType.Jumping then --if the player has jumped then
        prevjump = tick() --sets prevjump to this tick 
    end
end)
UserInputService.InputBegan:Connect(function(input) --when a player presses a key
    if input.KeyCode == Enum.KeyCode.Space then --if the keycode is space then
        if tick() - prevjump <= 0.25 then --if the current time - prevjump time is less than or = to 0.25 meaning its been less than 0.25 seconds since hes jumped then
            if hum:GetState() == Enum.HumanoidStateType.Freefall and not IsDoubleJumping then --if the player is freefalling and he hasn't double jumped yet then
                IsDoubleJumping = true --it sets doublejump to true meaning he just double jumped
                hum:ChangeState(Enum.HumanoidStateType.Jumping) --Changes the state of the humanoid to jumping again
            end
        end
    end
end)
#

thx

frigid martenBOT
#

studio** You are now Level 9! **studio

hasty wyvern
coral prairie
untold kiln
coral prairie
#

i guess its, well, explained, somewhat

hasty wyvern
#

ask me some questions

untold kiln
#

how do i get the length of a table

untold kiln
#

maybe like uh

#

try and code smhtn simple by urself

#

and if u need help u ask

hasty wyvern
#

for i,_ in pairs(table) do
print(i)

how many times it prints thats how many elements there are

untold kiln
#

cant u just do #table

hasty wyvern
#

whats that

untold kiln
#

but for dictionaries u cant

untold kiln
#

u can do #string

hasty wyvern
#

is that how many index there is in the table?

untold kiln
#

how many elements there are

hasty wyvern
#

kk

#

dictionaries are where u can store strings to values and all types of stuff

#

imma try and make one rq

#

lmk what u think

untold kiln
#

ok

#

btw im only joining this server to look back at the good ol days

#

so ill help u a bit more and im outta here

#

ask any questions you need answered

#

and u cant find a logical answer anywhere else

hasty wyvern
#

local Dictionary = {
One = 1,
Two = 2,
Three = 3
}

for i,v in pairs(Dictionary) do
print(i.." is "..v)
end

hasty wyvern
hasty wyvern
#

made it print

#

16:49:34.705 One is 1 - Server - Table:8
16:49:34.705 Three is 3 - Server - Table:8
16:49:34.705 Two is 2 - Server - Table:8

#

Do you think I have a good understanding of dictionaries?

untold kiln
untold kiln
#

why?

hasty wyvern
untold kiln
#

k yea

#

well u seem like ur chillin

hasty wyvern
untold kiln
#

i am a monkey

hasty wyvern
#

its ok

#

but

#

do you have the same issue I do/

#

?

hasty wyvern
#

local Dictionary = {
One = 1,
Two = 2,
Three = 3
}

local KeyOrder = {"One", "Two", "Three"}

for i,v in pairs(KeyOrder) do
print(Dictionary[v])
end

#

i did it with an array