I am currently working on a hockey-type game and am wondering how I could get the puck to shoot in the location that I click, and am having issues with bodyvelocity as it is new to me.
Server sided code:
script.Parent.Equipped:Connect(function()
script.Parent.SE.OnServerEvent:Connect(function(plr,power,mhp)
if game.Workspace.Puck:FindFirstChild("Attatched") then
game.Workspace.Puck.Attatched:Destroy()
game.Workspace.Puck.Canpick.Value = false
wait(.4)
game.Workspace.Puck.Canpick.Value = true
game.Workspace.Puck.CanCollide = true
end
local force = Instance.new("BodyVelocity")
force.MaxForce = Vector3.new(1,1,1) * math.huge
force.Velocity = mhp
force.Parent = game.Workspace.Puck
force.P = power
game.Debris:AddItem(force, .25)
end)
end)
Local script code
local player = game.Players.LocalPlayer
local ms = player:GetMouse()
local db = false
local shooting = false
local power = 20
local hitpos = ms.Hit.Position
local whatshoulddo = ""
ms.Button1Down:Connect(function()
power = 20
if db == false then
db = true
shooting = true
while shooting do
wait(.15)
power += 5
if power == 100 or shooting == false then
db = false
if game.Workspace.Puck:FindFirstChild("Attatched") then
if game.Workspace.Puck:FindFirstChild("Attatched").Part1 == player.Character.Stick.Blade then
print(power)
script.Parent.SE:FireServer(power, hitpos)
power = 20
shooting = false
break
else -- is for hitting, ignore
if power >= 40 then
print(power)
whatshoulddo = "Hit"
script.Parent.Send:FireServer(whatshoulddo, power)
power = 20
shooting = false
end
end
else -- is for hitting, ignore.
if power >= 40 then
print(power)
whatshoulddo = "Hit"
script.Parent.Send:FireServer(whatshoulddo, power)
power = 20
shooting = false
end
end
end
end
end
end)
ms.Button1Up:Connect(function()
shooting = false
end)
(Some of the localscript code is for a different purpose which I labelled.)