i made a script that allows the player to pick up a feather item and it makes them weightless. after the player picks it up a 10 second timer starts and they should be able to float only while holding space.
however the script i made somehow only lets the player float after the 10 second timer ends. I can’t seem to find out why thats happening, since the script is setup to where it only works while the task.wait(10) is running.
this is the script:
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local plrchar = script.Parent
local lclplayer = Players:GetPlayerFromCharacter(plrchar)
local RemoteEvent = script.RemoteEvent
local dbljump = script.Parent.MultipleJump
local active = false
RemoteEvent.OnClientEvent:Connect(function(player)
print("featherweight active")
active = true
local humanoid = plrchar:FindFirstChildOfClass("Humanoid")
if humanoid then
while task.wait(10) and active do
local jumpheight = humanoid.JumpHeight
local originalGravity = workspace.Gravity
local gravityChanged = false
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space and not gameProcessed then
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
--dbljump.Enabled = false
workspace.Gravity = 20
gravityChanged = true
end
end
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space and gravityChanged then
--dbljump.Enabled = true
workspace.Gravity = originalGravity
gravityChanged = false
end
end)
end)
workspace.Gravity = originalGravity
print("over")
active = false
end
end
end)
The script works thankfully but its only after the “over” is printed.