Hello Scripters!
I’m trying to recreate Mann Vs Machine, which for a small recap is pretty much just the PVE of Team Fortress 2 where you basically defend robots trying to drop a bomb in the other side. I am trying to replicate that one feature where a robot such as a Scout carries the bomb which is placed at the back of their body.
This is what I was hopping the script would do:
As you can obviously see here, this is what I want the bomb to be placed whenever an enemy touches the bomb, a perfectly 180 Degree angle(I think) of the bomb being attached to the NPC. Although this is what actually happens;
As you can see during testing, my boy Bloxxer incorrectly placed the bomb behind him, being in a weird position and orientartion.
As far as I know, I don’t really know how this is happening really. And for more information, a WeldConstraint is located inside of Bloxxer’s or the enemies torso and the bomb connects itself to the WeldConstraint if the enemy touches it.
This is a script inside of the bomb model itself which controls when the existing/living enemies should go to the hatchet to drop the bomb as well of connecting the bomb to it’s owner
local Players = game:GetService("Players")
local AllEnemiesFolder = workspace:WaitForChild("AllEnemies")
local Bomb = script.Parent
script.Parent.Touched:Connect(function(OnHit)
local Player = Players:GetPlayerFromCharacter(OnHit.Parent)
if not Player then
Bomb.Anchored = false
Bomb.CanCollide = false
local Owner = OnHit.Parent
Bomb.Position = Owner.HumanoidRootPart.Position
Bomb.Orientation = Bomb.Orientation + Vector3.new(0, math.rad(90), math.rad(90))
Bomb.CFrame = Bomb.CFrame + Vector3.new(-1, 0, 0)
Owner.Torso:FindFirstChild("WeldConstraint").Part1 = Bomb
for _, Enemy in pairs(AllEnemiesFolder:GetChildren()) do
if Enemy:IsA("Model") then
Enemy:SetAttribute("HasBomb",true)
end
end
elseif Player then
return
end
end)