So i have a minigolf script that works but it's not that good cause when your power is short like the game minigolf on roblox when you click it rolls super long it isnt like the minigolf game in roblox, so like if your power is short and you click it shoulden't roll so long it should stop when it's low velocity

heres the script:

repeat wait() until game.Players.LocalPlayer
local player = game.Players.LocalPlayer
repeat wait() until game.Players.LocalPlayer
local character = player.Character


local mouse = player:GetMouse()
local ball = game.ReplicatedStorage.Ball:Clone()
local canHitBall = true
local camera = workspace.CurrentCamera

ball.Parent = workspace

camera.CameraSubject = ball 
wait(1)
camera.CameraType = "Custom"
ball.Anchored = true

mouse.Button1Down:connect(function()
	if (canHitBall) then
		canHitBall = false
		ball.Anchored = false
		if ((ball.Position - mouse.hit.p).magnitude*8 < 200) then
			local tempP = (mouse.hit.p - ball.Position).unit * (((ball.Position - mouse.hit.p).magnitude)*8)
			local power = Vector3.new(tempP.X, 1, tempP.Z)
			ball.Velocity = power/2
			print("hit ball with str")
		else
			local tempP = (mouse.hit.p - ball.Position).unit * 200
			local power = Vector3.new(tempP.X, 1, tempP.Z)
			ball.Velocity = power/2
			print("hit max")
		end
	else
		print("Try again")
	end
end)

coroutine.resume(coroutine.create(function()
		local p = Instance.new("Part", ball)
		p.Anchored = true
		p.CanCollide = false
		p.Color = Color3.new(1,0,0)
		local SurfaceGui = Instance.new("SurfaceGui", p)
		SurfaceGui.Face = "Top"
		local Frame = Instance.new("Frame", SurfaceGui)
		Frame.BackgroundColor3 = Color3.new(255, 255, 255)
	while wait() do
		if (canHitBall) then
			local distance = ((ball.Position - mouse.hit.p).magnitude)
			p.Transparency = 1
			Frame.Transparency = 0
			if ((distance - 0.5) < 24) then
				p.Size = Vector3.new(1,0.1, (distance - 0.5))
				Frame.Size = UDim2.new(p.Size.X,0,1,0)
				p.CFrame = CFrame.new(Vector3.new(ball.Position.x, (ball.Position.Y-(ball.Size.Y/2)), ball.Position.z), Vector3.new(mouse.hit.p.x, (ball.Position.Y-(ball.Size.Y/2)), mouse.hit.p.z))*CFrame.new(0, 0, -distance/2)
			else
				p.Size = Vector3.new(1,0.1, 24)
				p.CFrame = CFrame.new(Vector3.new(ball.Position.x, (ball.Position.Y-(ball.Size.Y/2)), ball.Position.z), Vector3.new(mouse.hit.p.x, (ball.Position.Y-(ball.Size.Y/2)), mouse.hit.p.z))*CFrame.new(0, 0, -24/2)
			end
		else
			Frame.Transparency = 1
		end
	end
end))

while wait() do
	if (not canHitBall) then
		if (math.floor(math.abs(ball.Velocity.Z)) == 0) and (math.floor(math.abs(ball.Velocity.X)) == 0) then
			wait(2)
			if (math.floor(math.abs(ball.Velocity.Z)) == 0) and (math.floor(math.abs(ball.Velocity.X)) == 0) then
				canHitBall = true
			end
		end
	end
	
	if (math.abs(ball.Velocity.X) < 1) and (math.abs(ball.Velocity.Z) < 1) then
		ball.Velocity = Vector3.new(0, ball.Velocity.Y, 0)
	end
end

4 comments

0

Have you considered adjusting the friction of the ball?

0

nah, don't know how to

0

nah, don't know how to

0

Its in properties