Im trying to create a projectile onn a tool and shooot it forward but that just isnt working out for me
Either the projectile wonnt move (this like always happens when the game has been running for too long; too long meaning more than 3 seconds…)
or it shoot out then keep shooting same way (and it does the same with other projectile on other tools)
i triewd everything but it impossible
theory: something it wrong
here is my code if you even care it short:
Spine Shoot gear/ Sigular spine
local mytOols = script.Parent
local coolD = script.Parent.coolsdown
--local hUM = players[mytOols.Parent.Parent.Name].Character.Humanoid -- efficient as fu
mytOols.Activated:Connect(function()
if coolD.Value then
return
end
coolD.Value = true
local myPart = mytOols.Parent:FindFirstChild("HumanoidRootPart")
local SPINE = game.Workspace.Spike:Clone()
SPINE.CFrame = myPart.CFrame * CFrame.new(0,0,-5)
SPINE.CFrame *= CFrame.Angles(-1.5,0,0)
SPINE.Parent = game.Workspace
local shooting = Instance.new("BodyVelocity")
shooting.MaxForce = Vector3.one * math.huge
shooting.Velocity = myPart.CFrame.LookVector * 100
shooting.Parent = SPINE
local bruh = 5
repeat
mytOols.Name = bruh
task.wait(1)
bruh -= 1
until bruh == 0
mytOols.Name = "Spine Shoot"
coolD.Value = false
end)
Pole/ spray gear/Stream spikes
local running = game:GetService("RunService")
local myTOol = script.Parent
local spewSpew = myTOol.Handle.Attachment
local coolD = myTOol.coolsdown
local function SPEWING()
if spewSpew.Parent.Parent.Name == "Backpack" then
return
end
spewSpew.CFrame *= CFrame.Angles(0,0.5,0.1)
local dep = game.Workspace.Spike:Clone()
dep.CFrame = spewSpew.WorldCFrame
dep.Size *= 0.2
dep.Parent = game.Workspace
dep.Script.Enabled = true
dep.AssemblyLinearVelocity = spewSpew.WorldCFrame.UpVector * 100
end
myTOol.Activated:Connect(function()
if coolD.Value then
return
end
coolD.Value = true
local hUM = myTOol.Parent:FindFirstChild("Humanoid").Animator
local Animate = hUM:LoadAnimation(myTOol.Scary)
Animate.Priority = Enum.AnimationPriority.Action4
Animate:Play()
local mySUN = running.Heartbeat:Connect(SPEWING)
Animate.Stopped:Wait()
mySUN:Disconnect()
local bruh = 5
repeat
myTOol.Name = bruh
task.wait(1)
bruh -= 1
until bruh == 0
myTOol.Name = "Pole"
coolD.Value = false
end)```
Im thinking this could be a nice chalenge for devs to prove they know how to debuff programs
You didn’t give very much information so what i’ll assume is that you are trying to create a projectile that moves forward and falls with a curve since you said this:
What i did is added a shoot function for the shooting logic, it uses duration and range to determine how high and far the projectile should go. Im using applyImpulse but assemblyLinearVelocity does basically the same thing. We are basically cloning the projectile and setting the position of the projectile infront of the player, then we get the lookVector of the player which is a vector with each axis being a number from -1 to 1 and we apply the range. The force is calculated by dividing direction by duration to get the distance for each second of duration we have to travel. And we apply gravity logic for the curve. At the end i added the part as debris to it gets destroyed after a certain amount of time.
You can change the rest in this script how you want. I referred both tools in a single script in starterPlayerScripts. If there’s anything else that you want changed then please hit me up.
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player.Backpack
-- Change these to reference your own tools
local NormalTool = backpack.Tool
local SpewTool = backpack.Spew
-- Save tool names to revert the names later
local ToolName = NormalTool.Name
local SpewName = SpewTool.Name
-- Projectile logic
local duration = .5
local range = 100
-- Cooldowns
local cooldown = 5
local debounce = false
local function Shoot()
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end
-- Making a new projectile
local projectile = workspace.Spike:Clone()
projectile.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -5)
projectile.Parent = workspace
-- Applying force for projectile movement
print(humanoidRootPart.CFrame.LookVector)
local direction = humanoidRootPart.CFrame.LookVector * range
local force = direction / duration + Vector3.new(0, workspace.Gravity * duration * 0.5, 0)
projectile:ApplyImpulse(force * projectile.AssemblyMass)
projectile.Touched:Connect(function(hit)
projectile.Anchored = true
-- any other collision logic here
end)
-- Adding item as debris so it gets destroyed after 5 seconds
game.Debris:AddItem(projectile, 5)
end
-- Shoots a single projectile
NormalTool.Activated:Connect(function()
if debounce then return end
debounce = true
Shoot()
for i = cooldown, 1, -1 do
NormalTool.Name = i
task.wait(1)
end
NormalTool.Name = ToolName
debounce = false
end)
-- Keeps shooting until tool has been deactivated
SpewTool.Activated:Connect(function()
if debounce then return end
debounce = true
local spewingCon = runService.Heartbeat:Connect(Shoot)
SpewTool.Deactivated:Wait()
spewingCon:Disconnect()
for i = cooldown, 1, -1 do
SpewTool.Name = i
task.wait(1)
end
SpewTool.Name = ToolName
debounce = false
end)
local mytOols = script.Parent
local coolD = script.Parent.coolsdown -- coolD stand for coll dbeounce
local speed= 100
local cooldown = 5
--local hUM = players[mytOols.Parent.Parent.Name].Character.Humanoid -- efficient as fu
local function snake(myPart)
local SPINE = game.Workspace.Spike:Clone()
SPINE.CFrame = myPart.CFrame * CFrame.new(0,0,-5)
SPINE.CFrame *= CFrame.Angles(-1.5,0,0)
SPINE.Parent = game.Workspace
--local shooting = Instance.new("BodyVelocity") i hate apply impluse really really bad
--shooting.MaxForce = Vector3.one * math.huge
--shooting.Velocity = myPart.CFrame.LookVector * speed
--shooting.Parent = SPINE
local direction = myPart.CFrame.YVector * speed
local force = "I dont want gravityyy ;-;' i want anti garvity"
SPINE:ApplyImpulse(direction)
game.Debris:AddItem(SPINE, 5)
end
mytOols.Activated:Connect(function()
if coolD.Value then
return
end
coolD.Value = true
local myPart = mytOols.Parent:FindFirstChild("HumanoidRootPart")
snake(myPart)
for i = cooldown, 0, -1 do
mytOols.Name = i
task.wait(1)
end
mytOols.Name = "Spine Shoot"
coolD.Value = false
end)```
Okay i see, so you don’t want gravity, does that mean the part should fly in a straight line? I hope i got this right for you, you can leave out the myPart variable out. Just paste the function over your old one
local function snake()
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end
local SPINE = game.Workspace.Spike:Clone()
SPINE.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -5) * CFrame.Angles(-1.5,0,0)
SPINE.Parent = game.Workspace
local shooting = Instance.new("BodyVelocity")
shooting.MaxForce = Vector3.one * math.huge
shooting.Velocity = humanoidRootPart.CFrame.LookVector * speed
shooting.Parent = SPINE
game.Debris:AddItem(SPINE, 5)
end
Hmm strange, I don’t know why it would be doing that because the script should run fine. Are there any other scripts interfering. And does the full game freeze or just not being able to shoot?