so I have a problem, whenever a player in my game is idle and not moving they will fall through the ground a little and then pop back up repeatedly. This is a physics bug not a script error. I've decided to fix it by including a body velocity that takes off a large amount of the character's weight and to put it in their torso when they arent pressing any keys. That works however, my function for removing it does not work. Here are the two functions:
function hover()
if #game:GetService("UserInputService"):GetKeysPressed() == 0 then
if Player.Character.Torso then
script.BHov:Clone().Parent = Player.Character.Torso
elseif not Player.Character.Torso then
print("theres no torso here")
end
end
end
game:GetService("UserInputService").InputBegan:connect(function()
if Player.Character.Torso then
local l = Player.Character.Torso:GetChildren()
for i=1, #l do
if l.Name == "BHov" then
l:Remove()
end
end
elseif not Player.Character.Torso then
print("theres no torso here")
end
end)
game:GetService("UserInputService").InputEnded:connect(hover)
I did try if keypressed >=1 then and i also tried if keyspressed ~= 0 but neither work. |