I have recently made a a script that clones a brick and launches it out of a held item. However the script does not work and it returns with no errors. I really don't know what could be wrong with it, I've double checked to make sure all items are in their proper places, i differentiated between the cloned arrow and the arrow clone, i even spelled 'velocity' correctly.
local tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local bullet = game.ReplicatedStorage.bullets.arrow function pew () bullet:clone().Parent = tool local arrowb = script.Parent.arrow game.Debris:AddItem(arrowb, 2) arrowb.CFrame = tool.Handle.Cframe arrowb.CFrame = CFrame.new(arrowb.Position,mouse.Hit.P) local v = Instance.new ("BodyVelocity", arrowb) v.velocity = arrowb.CFrame.lookVector *90 v.maxForce = Vector3.new(math.huge, math.huge, math.huge) end tool.Activated:connect(pew)
Any ideas what could be wrong?
mouse.Hit.p should have a lowercase p.
I've tidied up the script a bit, removed unnecessary code and commented things I've changed.
local tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local bullet = game:GetService("ReplicatedStorage").bullets.arrow --Changed to use GetService() function pew() local arrow = bullet:clone() -- Should index this as you create it arrow.Parent = tool -- GetService for Debris game:GetService("Debris"):AddItem(arrow, 2) -- Only need to set the arrow CFrame once... arrow.CFrame = CFrame.new(tool.Handle.Position, mouse.Hit.p) -- lower case p local v = Instance.new ("BodyVelocity", arrow) v.velocity = arrow.CFrame.lookVector *90 v.maxForce = Vector3.new(math.huge, math.huge, math.huge) end tool.Activated:connect(pew)