Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalScript doesn't create BodyVelocity. Why?

Hey. I want to make the player glide(fall slower) using body velocity: A script creates the BodyVelocity, it parents it to the UpperTorso and it sets its properties, but for some reason the script doesn't create the BodyVelocity. Here's the script:

local userinputservice = game:GetService("UserInputService")

player = game.Players.LocalPlayer
local character = player.Character
mouse = player:GetMouse()
humanoid = character.Humanoid

userinputservice.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.Space then
		print("Gliding now...")
		animTrack:Play()
		print("playing animtrack")
		local f = Instance.new("BodyVelocity")
		print("f created")
		f.Parent = character.UpperTorso
		print("UpperTorso it is")
		f.Name = "GlideHelper"
		f.MaxForce = Vector3.new(0, 99999, 0)
		f.P = 1250
		f.Velocity = Vector3.new(0, -10, 0)
		print("properties set")
	end
end)

It prints everything in that code but nothing works, except the animTrack. I've checked the UpperTorso in-game: There is not BodyVelocity there when I press Space. So... help?

1 answer

✓ Accepted answer

Try this!

local userinputservice = game:GetService("UserInputService")

player = game.Players.LocalPlayer
local character = player.Character
mouse = player:GetMouse()
humanoid = character.Humanoid

userinputservice.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.Space then
        print("Gliding now...")
        animTrack:Play()
        print("playing animtrack")
        local Velocity = Instance.new("BodyVelocity", character:WaitForChild("Head"))
        Velocity.Name = "GlideHelper"
        Velocity.MaxForce = Vector3.new(0, 99999, 0)
        Velocity.P = 1250
        Velocity.Velocity = Vector3.new(0, -10, 0)
    end
end)

2 comments

0

It works :D Thanks!!

0

It is better to set the Parent than pass the variable into Instance.new() (137 times slower) Source: https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296/2

This discussion is preserved as it was. New answers, comments, and votes are closed.