Ball Attack not working

So… I’m trying to make a Ball Attack that go to where the mouse is, and if the ball touch any wall, the ball is deleted.

When the Ball is spawned, it go to a random place and not to where the mouse is.

I don’t know what to do, is anything wrong with my script?

This script is inside ServerScriptService

Events.Hasty.Shadow.ShadowQ.OnServerEvent:Connect(function(Player, Mouse)
	local ShadowBall = Attacks.Hasty.Shadow.ShadowQ:Clone()
	ShadowBall.CFrame = Player.Character:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(0,0,-3)
	ShadowBall.Parent = game.Workspace
	ShadowBall.Anchored = false
	local PlayerAttacking = Instance.new("StringValue")
	PlayerAttacking.Parent = ShadowBall
	PlayerAttacking.Name = "PlayerAttacking"
	PlayerAttacking.Value = Player.Name
	local TweenTransparency = TweenService:Create(ShadowBall, TweenInfo.new(0.25), {Transparency = 1})
	local HRP = Player.Character:FindFirstChild("HumanoidRootPart")
	local LinearVelocity = ShadowBall.Attachment.LinearVelocity
	LinearVelocity.MaxForce = math.huge
	LinearVelocity.VectorVelocity = HRP.CFrame.LookVector * 50
	wait(3)
	if ShadowBall then
		TweenTransparency:Play()
		wait(0.25)
		ShadowBall:Destroy()
	end
end)

This one is in StarterCharacterScripts

UIS.InputBegan:Connect(function(input)
	if (UIS:GetFocusedTextBox()) then
		return
	end
	if input.KeyCode == Enum.KeyCode.Q and dbQ then
		dbQ = false
		local Mouse = game.Players.LocalPlayer:GetMouse()
		game.ReplicatedStorage.Attacks.Hasty.Shadow.ShadowQ:FireServer(Mouse.Hit.LookVector)
		wait(3)
		dbQ = true
	end
end)

This script is inside the ball

local ShadowBall = script.Parent
local db = true
ShadowBall.Touched:Connect(function(Hit)
	if Hit.Name == "HitBox" and db then
		db = false
		local Enemy = Hit.Parent
		local Damage = (game.Players:FindFirstChild(script.Parent:FindFirstChild("PlayerAttacking").Value):FindFirstChild("Stats"):FindFirstChild("SubDamage").Value*1.5) - Enemy:FindFirstChild("Defense").Value
		if Damage <= 0 then
			Damage = 1
		end
		Enemy.Health.Value = Enemy.Health.Value - Damage
		script.Parent:Destroy()
	end
end)

The Ball should spawn in front of the Player when Q is press and go to where the mouse is, if hit an Enemy, it damage the enemy, but if hit a wall, the ball is destroyed.

1 Like

You’re using mouse.Hit.LookVector instead of mouse.Hit.Position

game.ReplicatedStorage.Attacks.Hasty.Shadow.ShadowQ:FireServer(Mouse.Hit.Position)

In your server side code, you’re not even using the mouse info you sent anywhere

ShadowBall.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position, Mouse) * CFrame.new(0, 0, -3)

Lastly your linear velocity is based off where your rootpart is looking, so it won’t go toward where you aimed.

LinearVelocity.VectorVelocity = ShadowBall.CFrame.LookVector * 50

These lines of code should fix your issue. Give it a try!

1 Like

Thank you for trying to help, but the ball still not going to the mouse…
Here a video
robloxapp-20240604-2230145.wmv (801.9 KB)

1 Like

From the video, I could be wrong, but it looks like the LookVector is still being sent, instead of the Position. Make sure you check that out and change it out if needed.

I changed those lines

game.ReplicatedStorage.Attacks.Hasty.Shadow.ShadowQ:FireServer(Mouse.Hit)
ShadowBall.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position)
LinearVelocity.VectorVelocity = Mouse.LookVector * 50

And now it’s almost working, the Ball just go a little down of where the mouse is.

Change LinearVelocity.VectorVelocity = Mouse.LookVector * 50 to LinearVelocity.VectorVelocity = Mouse.Position * 50. It should go straight to where your cursor is at.

EDIT: I made a sampe tool, using Mouse.Position instead of LookVector. Notice how it goes exactly where my mouse is: Watch Tool Demo | Streamable
DemoTool.rbxm (3.3 KB)

The Ball doesn’t spawn and there isn’t any error.

Please see my edited message. It should hopefully resolve this once and for all.

Finally, it’s working :D, Thank you for the help.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.