How do I fix my current script?

The script I made, meant to mimic gravity getting more intense as you fall, but it keeps running when landed. Where’d I go / do wrong?

local plr = script.Parent
local hum = script.Parent:WaitForChild(“Humanoid”)
local times = 0

function freefall()
repeat workspace.Gravity = workspace.Gravity +0.981
times = times + 0.981
until times == 196.2
end

hum.StateChanged:Connect(function(ENUM)
if ENUM == Enum.HumanoidStateType.Freefall then
freefall()
elseif ENUM == Enum.HumanoidStateType.Landed then
workspace.Gravity = 196.2

end

end)

1 Like

Mind showing the whole script? I can’t seem to find where you got hum from.

2 Likes

Also,how did got that “times” from?

There you go, forgot to add that in…

local plr = script.Parent
local hum = script.Parent:WaitForChild(“Humanoid”)
local times = 0

function freefall()
repeat workspace.Gravity = workspace.Gravity +0.981
times = times + 0.981
until times == 196.2
end

hum.StateChanged:Connect(function(ENUM)
if ENUM == Enum.HumanoidStateType.Freefall then
freefall()
elseif ENUM == Enum.HumanoidStateType.Landed then
workspace.Gravity = 196.2

end
end)

I didnt change anything,i just made it code,not text.

1 Like

Don’t blame me for adding the Times variable though - not like you would. I tried to change the code.

Next time use Lua code blocks.

What is the script’s parent?

It’s in starter character scripts. dunno where else to put it…

Get used to indexing character instead of plr.
Also, get in the habit of using game.Workspace instead of workspace.

There are two parameters for hum.StateChanged. Read more here: Humanoid - State Changed

Try reading the source I gave you, use both parameters, and see if that helps you.

2 Likes

What would game.Workspace help me out with? I prefer workspace as its shorter.

game.Workspace doesn’t really help or change anything, it’s just better practice.

Okay, I’ll be trying that somepoint.

1 Like
game.Workspace.ChildAdded:connect(function(Character)
    if Character.Name == game.Workspace:FindFirstChild("Character.Name") then
        Character = Character   
    end
end)
--Player Variable
local Hum = Character:FindFirstChild("Humanoid")
local times = 0

Hum.StateChanged:connect(function(Freefall)
    repeat workspace.Gravity = game.Worksapce.Gravity +0.981
    times = times + 0.981
    until times == 196.2
end)--Freefall

Hum.StateChanged:Connect(function(ENUM)
    if ENUM == Enum.HumanoidStateType.Freefall then
        Freefall()
elseif ENUM == Enum.HumanoidStateType.Landed then
        game.Workspace.Gravity = 196.2
    end--Enum,if statement
end)--Enum

Maybe this code will work…correct me if i’am wrong,also thanks for waiting.]
Also,i think you should put this script in Workspace or ServerScriptService.Hope this helps!

1 Like