part.Size = Vector3.new((script.Parent.Shotpart.Attachment1.Position-character.Head.Position).Magnitude, 0.25, 0.25)
part.Position = CFrame.lookAt(character.Head.Position,character.Head.Position)
No, you didnât exactly get it right here.
Remove this line.
And CFrame.lookAt requires the starting position and the ending position. Youâre close, but you need:
The size should work.
So it should be this?
script.Parent.DetectionPart.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if not player.TeamColor ~= BrickColor.new("Bright red") then
local part = Instance.new("Part", script.Parent)
local mesh = Instance.new("CylinderMesh", part)
part.Size = Vector3.new((script.Parent.Shotpart.Attachment1.Position-character.Head.Position).Magnitude, 0.25, 0.25)
part.CFrame = CFrame.lookAt(script.Parent.Shotpart.Position, character.Head.Position)
end
end
end)
I donât recommend using a mesh and changing the shape of the part to Enum.PartType.Cylinder
. It should work, though. Go try it out.
Okay. This is what happened:
In that case, what is the output?
I think the part is unanchored. You should add a part.Anchored = true
line.
Oh wait I moved it to a baseplate because I couldnât see if there were any errors in the main game because a lot of stuff gets put in the console and uh. This happened.
If I anchor it, it turns out like this.
Thatâs what I thought. The part does need to be anchored.
Also, I noticed that the CFrame statement is off by a bit. New code:
script.Parent.DetectionPart.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if not player.TeamColor ~= BrickColor.new("Bright red") then
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
local mag = (script.Parent.Shotpart.Attachment1.Position-character.Head.Position).Magnitude
part.Size = Vector3.new(mag, 0.25, 0.25)
part.CFrame = CFrame.lookAt(script.Parent.Shotpart.Position + (script.Parent.Shotpart.CFrame.LookVector * mag/2), character.Head.Position)
part.Parent = workspace
task.wait(2)
part:Destroy()
end
end
end)
I fixed this issue as well in the new code.
This is intentional. You can change the time through the wait statement.