Hey, i have 3 codes which i use for ball shooting but it seems like the psychics is broken completely:
A local script of the ball
local parent = script.Parent
local bodyforce = Instance.new("VectorForce", parent)
bodyforce.Force = Vector3.new(0,0,0)
local sendStopped
game:GetService("RunService").RenderStepped:Connect(function()
if (parent.AssemblyLinearVelocity.Magnitude < 0.05) then
parent.AssemblyLinearVelocity = Vector3.new(0,0,0)
if not sendStopped then
--game.ReplicatedStorage.Events.BallStopped:FireServer()
sendStopped = true
end
else
sendStopped = false
end
bodyforce.Force = Vector3.new(0.1*(-parent.AssemblyLinearVelocity.X), 0.1*(-parent.AssemblyLinearVelocity.Y), 0.1*(-parent.AssemblyLinearVelocity.Z))
end)
Script for getting the power the ball is shot with:
-- Power Bar Variables
local Power = 0
local stopPowerChecking = false
local canShot = true
local ArrowStop = false
local powerHud = hud.PowerBar
uiService.InputBegan:Connect(function(input)
if play then
if input.KeyCode == Enum.KeyCode.M then -- Main Menu related, ignore
if not inMainMenuOpenProcess and play then
MainMenuHud(mainmenuHud.Visible)
end
end
if input.UserInputType == Enum.UserInputType.MouseButton1 and not inMainMenu and not uiService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) and canShot then
local viewportY = camera.ViewportSize.Y
local scaleOfAs = 0.5
local scaleOfMouseY = mouse.Y/viewportY
local max, min = scaleOfMouseY+(scaleOfAs/2), scaleOfMouseY-(scaleOfAs/2)
ArrowStop = true
while true do
if uiService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) or inMainMenuOpenProcess or inMainMenu then
break;
end
if stopPowerChecking then
break;
end
scaleOfMouseY = mouse.Y/viewportY
if max < 0.15 then
max = 0.15
elseif min > 0.8 then
min = 0.8
end
if scaleOfMouseY > max then
max = scaleOfMouseY
min = max-scaleOfAs
elseif scaleOfMouseY < min then
max = scaleOfMouseY+scaleOfAs
min = scaleOfMouseY
end
Power = 1-((scaleOfMouseY-min)/(max-min))
powerHud.PowerHolder.PowerBar.Position = UDim2.new(Power-(powerHud.PowerHolder.PowerBar.Size.X.Scale/2), 0, powerHud.PowerHolder.PowerBar.Position.Y.Scale, 0)
powerHud.PowerHolder.PowerArrow.Position = UDim2.new(Power-((powerHud.PowerHolder.PowerArrow.Size.X.Scale/2)+(powerHud.PowerHolder.PowerBar.Size.X.Scale/2)), 0, powerHud.PowerHolder.PowerArrow.Position.Y.Scale, 0)
wait(0.01)
end
end
end
end)
uiService.InputEnded:Connect(function(input)
if play then
if not uiService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) and not inMainMenuOpenProcess and not inMainMenu and input.UserInputType == Enum.UserInputType.MouseButton1 and canShot then
canShot = false
game.ReplicatedStorage.Events.ShotBall:FireServer(Power, arrow.CFrame.LookVector.X, arrow.CFrame.LookVector.Y, arrow.CFrame.LookVector.Z)
stopPowerChecking = true
ArrowStop = false
arrow.Decal.Transparency = 1
local ball = workspace[localPlayer.Name].Minge
while true do
wait(0.01)
if ball.AssemblyLinearVelocity.Magnitude < 0.05 then
arrow.Decal.Transparency = 0
canShot = true
stopPowerChecking = false
end
end
end
end
end)
-- Arrow Moving
mouse.Move:Connect(function()
if ArrowStop then
return;
end
local playerBall = workspace[localPlayer.Name]:FindFirstChild("Minge")
if playerBall == nil then
return;
end
local newPos = Vector3.new(mouse.Hit.X, playerBall.Position.Y, mouse.Hit.Z)
arrow.CFrame = CFrame.new(playerBall.Position, newPos)*CFrame.new(0, 0, -7)
end)
In a server script:
game.ReplicatedStorage.Events.ShotBall.OnServerEvent:Connect(function(player, power, x, y, z)
local realpower, yrealpower = workspace.Settings.MaxVelocity.Value*power, workspace.Settings.MaxJumpPower.Value*power
local direction = Vector3.new(x*realpower, yrealpower, z*realpower)
local ball = workspace[player.Name].Minge
ball.AssemblyLinearVelocity = direction
end)
So basically what i do with these codes is shot a ball for everyone but the psychics is completely broken for some reason and i cannot figure it out.
A video to see how it works:
robloxapp-20220328-1358061.wmv (2.8 MB)