c = script.Parent.click debounce = true pp = script.Parent.Barrel.Position script.Parent.click.ClickDetector.MouseClick:connect(function() if debounce == true then c.BrickColor = BrickColor.new("Really red") debounce = false b = Instance.new("Part", game.Workspace) f = Instance.new("BodyThrust", b) fire = Instance.new("Fire", b) b.Name = "Canon Ball" b.BrickColor = BrickColor.new("Really black") b.Shape = "Ball" b.Size = Vector3.new(2, 2, 2) b.Position = Vector3.new(pp.X , pp.Y , pp.Z + 2.5) f.Force = Vector3.new(0, 0, 10000) b.Touched:connect(function(hit) if hit.Parent then if hit.Parent.Name == barrel then print "h" end else e = Instance.new("Explosion", b) e.Position = b.Position b:Destroy() print(hit.Name) end end) wait(5) debounce = true c.BrickColor = BrickColor.new("Bright green") end end)
It fires where the cannon was when the game first loaded and not where the cannon is at the moment. I tried to use a while true do loop for the position but it didnt run because it was doing the loop. - Thanks
Sorry guys im stupid I found out that the variable was declared outside the function and put pp in the function. Ill hesitate before posting here in the future.