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

How do I make a "free" moving velocity?

local player = script.Parent.Parent.Parent
local char = player.Character
local colors = {"Bright red","Bright orange","Bright yellow","Bright green","Bright blue","Bright violet","Institutional white","Medium stone grey","Dark stone grey","Really black"}
local color = 1
local speed = 60
local down = false
local jdeb = false
local cam = workspace.CurrentCamera
local sspeed = speed
local force

function UpdateColor() if char:findFirstChild("Marble") ~= nil then char.Marble.BrickColor = BrickColor.new(colors[color]) end end
function SetSpeed(v) char.Marble.BodyVelocity.velocity = v end

script.Parent.Selected:connect(function(mouse)
char.Humanoid.PlatformStand = true
local p = Instance.new("Part")
p.Name = "Marble"
p.Position = char.Torso.Position
p.Shape = 0
p.Transparency = 0.5
p.Size = Vector3.new(7,7,7)
p.BrickColor = BrickColor.new(colors[color])
p.TopSurface = "Smooth"
p.BottomSurface = "Smooth"
p.Parent = char
local w = Instance.new("Weld")
w.Parent = p
w.Part0 = p
w.Part1 = char.Torso
w.C0 = CFrame.new(Vector3.new(0,0,0))
local b = Instance.new("BodyVelocity")
b.velocity = Vector3.new(0,0,0)
b.maxForce = Vector3.new(3e+004, 3e+004, 3e+004)
b.Parent = p
force = b
cam.CameraSubject = char.Torso
cam.CameraType = "Track"

mouse.KeyDown:connect(function(key) 
if key == "q" then if color > 1 then color = color-1 UpdateColor() end end
if key == "e" then if color < #colors then color = color+1 UpdateColor() end end



end)

mouse.KeyUp:connect(function(key) if key == "z" then speed = sspeed end end)

mouse.Button1Down:connect(function() 
down = true 
force.velocity = (mouse.Hit.p-char.Torso.Position).unit*speed
end)


mouse.Button1Up:connect(function() down = false 
	SetSpeed(Vector3.new(0,0,0))  -- This is where the script slows the ball down to 0 speed, I would like it to roll and gradualy slow down at this point.
	-- It would be best if the ball rolled "freely", so if stopped on a ramp, it would roll down.
end)

mouse.Move:connect(function() if down then force.velocity = (mouse.Hit.p-char.Torso.Position).unit*speed end end) 

end)

script.Parent.Deselected:connect(function() cam.CameraSubject = char.Humanoid cam.CameraType = "Custom" pcall(function() char.Marble:remove() char.Humanoid.PlatformStand = false end)end)

What I need included in this script is also noted next to the line, but here it is again:

SetSpeed(Vector3.new(0,0,0))  -- This is where the script slows the ball down to 0 speed, I would like it to roll and gradualy slow down at this point.
	-- It would be best if the ball rolled "freely", so if stopped on a ramp, it would roll down.

The script is a LocalScript, inside a tool.

3 comments

0

Thanks for the -1, so appreciated :)

1

I think they're giving you -1 because you don't start out with an explanation of what you want; they're just seeing a huge script. Most of the script is irrelevant to your question (I essentially didn't read it, except for a few lines).

0

This is the ugliest code I have ever seen *facepalm

1 answer

I think removing the BodyVelocity (or disabling it) would be best. Do this by setting maxForce to Vector3.new(0,0,0). Don't forget to restore the original maxForce when you want it to move again.

If it's not slowing down fast enough while BodyVelocity is disabled, you could set the BodyVelocity.velocity to Vector3.new(0,0,0) as you're doing now and then set the maxForce to, say, Vector3.new(40,40,40)

5 comments

0

Thank you, finally someone helping me with this, I've been bumpin g this quite a few times on the ROBLOX Scripting forums, but nobody managed to help me out with it. I really appreciate your time. :)

0

Yes, now I managed to get the script working just the way I needed it to, but now it doesn't seem to be working online, but works in studio... :/

0

Is it in a LocalScript?

0

It is, yes

0

Press F9 while online to see the Developer Console; it'll show you any errors your script encounters. I notice that you're not using any :WaitForChild() or "wait()" commands, so it could be that your script is referring to things that haven't been loaded by the time the script runs (a common difference between Studio and online)

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