I've made a script to shoot a projectile out of the top of my tool. I want to damage players when they come into contact with it.
The problem is my positioning doesn't work right server-side due to latency issues. So I have to move the projectile into the workspace and position it using a localscript. Now if I run this block of code in a localscript it works perfectly fine. It prints test when anything is touched by the projectile.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = ReplicatedStorage:WaitForChild("projectileFire")
local projectiles = game.Players.LocalPlayer.Backpack.Projectiles:GetChildren()
local blowTip = script.Parent.Body.Tube.TubeTop.CFrame
local projectile = projectiles[1]
projectile.Parent = game.Workspace
projectile.CFrame = blowTip * CFrame.new(2, 0, 0)
local thrust = Instance.new("BodyVelocity")
local direction = blowTip.LookVector
thrust.Parent = projectile
thrust.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
thrust.Velocity = CFrame.new(player2.Character.HumanoidRootPart.CFrame.p, mouse.Hit.p).lookVector * 200
projectile.Touched:Connect(
function(hit)
print("Test")
end
)
game:GetService("Debris"):AddItem(thrust, 0.1)
game:GetService("Debris"):AddItem(projectile, 3)
Now I have a remote set up to send the required data for propelling my projectile. Here is the code for both the local and server scripts currently.
-- LOCALSCRIPT CODE
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = ReplicatedStorage:WaitForChild("projectileFire")
local projectiles = game.Players.LocalPlayer.Backpack.Projectiles:GetChildren()
local blowTip = script.Parent.Body.Tube.TubeTop.CFrame
local projectile = projectiles[1]
projectile.Parent = game.Workspace
projectile.CFrame = blowTip * CFrame.new(2, 0, 0)
shootEvent:FireServer(mouse.Hit.p, projectile)
-- SERVER SCRIPT CODE
local function shot(player, mouse, projectile)
local blowTip = script.Parent.Body.Tube.TubeTop.CFrame
local thrust = Instance.new("BodyVelocity")
local direction = blowTip.LookVector
thrust.Parent = projectile
thrust.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
thrust.Velocity = CFrame.new(player.Character.HumanoidRootPart.CFrame.p, mouse).lookVector * 200
projectile.Touched:Connect(
function(hit)
print("Test")
end
)
game:GetService("Debris"):AddItem(thrust, 0.1)
game:GetService("Debris"):AddItem(projectile, 3)
end
game.ReplicatedStorage.projectileFire.OnServerEvent:Connect(shot)
It's firing and propelling the projectiles as expected, but not printing my string. That leads me to believe that there's something going on with the touched event. I can't for the life of me figure out what that is. Any help is appreciated!

1 comment
Actually, there's nothing wrong with his Touched event. It works the exact same as the code you provided.