Why are some parts going through the baseplate

i’ve got problem with the mags going through the baseplate
some of the mags collide with baseplate

i don’t quite get it, can collide is literally on, and i dont change the collisions

Could you show us the code that handles the magazines?

its literally this
image

Just to make sure it’s nothing weird going on with roblox could you add this:

clone.Anchored = true
wait(2)
clone.Anchored = false

if they still fall after being unanchored then something else is causing this.

its not anchored
and i want to add physics
also im not messing with can collide

Can you add the code please?
This is just verifying that it’s not something with the model being loaded into workspace after being cloned.

nope it still goes through the baseplate after the third one

Is it possible to see the entire script?

yeah sure, but im kinda doubting anything else is affecting the collision

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CollectionService =  game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")

local Janitor = require(ReplicatedStorage.Janitor)
local IKArm = require(ServerStorage.R6.Arm)

local findChar = require(ServerStorage.findCharModule)
local BodyPartControl = require(ServerStorage.PlayerBodyParts)

local tweenInfo = TweenInfo.new(.25)

local GuardAnimations = ServerStorage.GuardAnimations
local ShootAnim = GuardAnimations.Shoot
local ReloadAnim = GuardAnimations.Reload
local IdleAnim = GuardAnimations.Idle
local BoredAnim = GuardAnimations.Bored

--assets
local GuardAssets = ServerStorage.GuardAssets
local bullet = GuardAssets.Bullet
local mag = GuardAssets.Mag

local rglv = ServerStorage.RedGreenLight

--values
local targetChange = 5 --target change
local reloadDelay = 2.7 -- reload delay
local ammoCount = 7 -- ammo count

local Guard = {}
Guard.__index = Guard

Guard._janitor = Janitor.new()
Guard.Guards = {}
Guard.Tag = "Guard"

Guard.ShootingChar = {}

local function getIndex(instance)
	for i, v in ipairs(Guard.Guards) do
		if v.guard == instance then
			return i
		end
	end
end

local function resetArmPos(info)
	local tween = TweenService:Create(info.rIK._Shoulder,tweenInfo,{C0 = info.rIK._OriginalShoulderC0})
	tween:Play()
	tween.Completed:Connect(function()
		info.rIK._Shoulder.C0 = info.rIK._OriginalShoulderC0
		tween:Destroy()
	end)
end

function Guard.new(instance)
	local Animator = instance.AnimationController.Animator
	local self = setmetatable({
		guard = instance, target = nil, targetChange = 0, reloadDelay = 0, shooting = false, reloading = false, ammoCount = ammoCount, cancelReload = true, idle = false, idleCooldown = time() + math.random(5,10),
		Animator = Animator, rIK = IKArm.new(instance, "Right"),
		Animations = {Shoot = Animator:LoadAnimation(ShootAnim), Reload = Animator:LoadAnimation(ReloadAnim), Idle = Animator:LoadAnimation(IdleAnim), Bored = Animator:LoadAnimation(BoredAnim)}
	}, Guard)
	table.insert(Guard.Guards,self)
	Guard._janitor:LinkToInstance(self.guard,true)
	self.Animations.Idle:Play()
	return self
end

function Guard.old(instance)
	local index = getIndex(instance)

	if index then
		local info = Guard.Guards[index]
		table.remove(Guard.Guards,index)

		info.rIK:Destroy()

		for _, anim in pairs(info.Animator:GetPlayingAnimationTracks()) do
			anim:Stop()
		end

		if table.find(Guard.ShootingChar, info.target) then
			table.remove(Guard.ShootingChar, table.find(Guard.ShootingChar,info.target))
		end

		resetArmPos(info)
	end
end

function Guard:Start()
	for _, instance in pairs(CollectionService:GetTagged(Guard.Tag)) do
		Guard.new(instance)
	end

	self._janitor:Add(
		RunService.Heartbeat:Connect(function()
			self:HeartbeatUpdate()
		end), "Disconnect"
	)
end

function Guard:Stop()
	for _, v in pairs(CollectionService:GetTagged(Guard.Tag)) do
		CollectionService:RemoveTag(v,Guard.Tag)
	end
	table.clear(Guard.ShootingChar)
	self._janitor:Cleanup()
end

function Guard:Shoot(info, random)
	if info.shooting == false then --if not shooting

		--cancel reload if isn't halfway and target is within reload range
		if info.reloading == true and info.ammoCount > 2 and info.cancelReload == true and findChar.checkChar(info.guard, random, 125) then
			--cancel reloading
			info.Animations.Reload:Stop()
			print("cancel reload")
		end

		if info.reloading == false then
			info.shooting = true
			info.target = random
			table.insert(self.ShootingChar, random)

			info.Animations.Bored:Stop()

			info.Animations.Shoot:Play()

			--change shooting animation
			local sc
			sc = info.Animations.Shoot:GetMarkerReachedSignal("shoot"):Connect(function()
				info.ammoCount -= 1
				--BodyPartControl.ShootChar(info.guard,random)
				print('shoot')
				sc:Disconnect()
			end)
			local ss
			ss = info.Animations.Shoot.Stopped:Connect(function()
				info.targetChange = time() + targetChange
				info.reloadDelay = time() + reloadDelay
				info.idleCooldown = time() + math.random(5,10)
				task.delay(.2,function()
					info.shooting = false
					table.remove(self.ShootingChar, table.find(self.ShootingChar,random))
				end)
				ss:Disconnect()
			end)
		end
	end
end

function Guard:Reload(info)
	if info.reloading == false and info.ammoCount < ammoCount and info.shooting == false then
		info.reloading = true
		info.cancelReload = true
		resetArmPos(info)
		print('reload')

		info.Animations.Bored:Stop()

		info.Animations.Reload:Play()

		local cr
		cr = info.Animations.Reload:GetMarkerReachedSignal("Cancel"):Connect(function()
			info.cancelReload = false
			print("can't cancel")
			cr:Disconnect()
		end)
		
		local hm 
		hm = info.Animations.Reload:GetMarkerReachedSignal("HideMag"):Connect(function()
			info.guard["Deagle"]["Mag"].Transparency = 1
			local clone = mag:Clone()
			clone.Position = info.guard["Deagle"]["Mag"].Position
			clone.Anchored = false
			clone.Parent = workspace
			clone.LinearVelocity.VectorVelocity = Vector3.new(math.random(5,50),math.random(5,50),math.random(5,50))
			Debris:AddItem(clone.LinearVelocity,1)
			hm:Disconnect()
		end)
		
		local sm
		sm = info.Animations.Reload:GetMarkerReachedSignal("ExposeMag"):Connect(function()
			info.guard["Deagle"]["Mag"].Transparency = 0
			sm:Disconnect()
		end)

		local rc
		rc = info.Animations.Reload.Stopped:Connect(function()
			if info.Animations.Reload.TimePosition == info.Animations.Reload.Length then
				info.ammoCount = ammoCount
				print("done")
			end
			info.reloading = false
			info.idleCooldown = time() + math.random(5,10)
			rc:Disconnect()
		end)
	end
end

function Guard:Idle(info)
	if info.reloading == false and info.ammoCount >= ammoCount and info.shooting == false and info.idle == false and info.idleCooldown <= time() then

		info.idle = true
		info.target = nil
		resetArmPos(info)
		print('idle')

		info.Animations.Bored:Play()

		local bc
		bc = info.Animations.Bored.Stopped:Connect(function()
			info.idle = false
			info.idleCooldown = time() + math.random(5,10)
			bc:Disconnect()
		end)

	end
end

function Guard:HeartbeatUpdate()
	for _, info in ipairs(self.Guards) do
		local npcs, moving = findChar.checkAll(info.guard, 250, self.ShootingChar)
		if #npcs > 0 then --if npc nearby
			if rglv:GetAttribute("RedLight") then
				if info.ammoCount > 0 then --if ammo above 0
					if #moving > 0 then --if any moving players
						local random = moving[math.random(0,#moving)]
						if random then--finds a random moving npc
							self:Shoot(info,random)
						end
					else --if no one is moving
						if info.reloadDelay <= time() then
							self:Reload(info)
						end
						self:Idle(info)
					end
				else --no ammo left
					self:Reload(info)
				end
			else --if its green light 
				self:Reload(info)
				self:Idle(info)
			end
			if info.idle == false then -- doesn't look at player while idle
				if table.find(npcs,info.target) then --if target is in range
					if info.targetChange <= time() and info.shooting == false and info.reloading == false then --if time to switch targets
						table.remove(npcs,table.find(npcs,info.target)) --removes current target
						if #npcs > 0 then
							local random = npcs[math.random(0,#npcs)]
							if random then --find another random target
								info.target = random
								info.targetChange = time() + targetChange
							end
						end
					end
					if info.reloading == false then --only tracks hand if its not reloading or idle
						TweenService:Create(info.rIK._Shoulder, tweenInfo, {C0 =  info.rIK:Solve(info.target.PrimaryPart.Position)}):Play()
					end
					TweenService:Create(info.guard.PrimaryPart, tweenInfo, {CFrame = CFrame.lookAt(info.guard.PrimaryPart.Position, info.target.PrimaryPart.Position)}):Play()
				else --if target not found
					if info.shooting == false and info.reloading == false then -- it doesn't pick a target while its shooting or reloading
						local random = npcs[math.random(0,#npcs)]
						if random then --find another random target
							info.target = random
							info.targetChange = time() + targetChange
						end
					end
				end
			end
		else--if no npc nearby
			info.target = nil
			if info.reloadDelay <= time() then
				self:Reload(info)
			end
			self:Idle(info)
		end
	end
end

CollectionService:GetInstanceAddedSignal(Guard.Tag):Connect(Guard.new)
CollectionService:GetInstanceRemovedSignal(Guard.Tag):Connect(Guard.old)

return Guard

its in the reload function

type or paste code here

I’m at a loss is all I can really say, I can only assume that this is a issue with meshpart collisions.

If I had to offer an idea then it would be this:
Put the Mag into a model, then cover the Mag mesh with a BasePart and make it invisible. Weld the mag and invisible part together that way you have a more “stable” collision box.

Change up the code to support CFraming the model via PrimaryPart after being Parented and it should hopefully work.

I wish you the best of luck.

1 Like

i have it set to box collision, i dont think anything else would of make the mag go through the baseplate

yeah, this is just so strange, though i’ve tested it with parts and they work so far

i’ve tried your method but it doesn’t quite work
i basically welded 2 parts together, and they are both floating i even unanchored them


wait nvm it works like a charm

How big is the invisible part?
Because it seems like you made it fairly large.

yeah you’re solution works, im not sure why the mesh collision works for part of the time and then just goes into the ground, im betting its probably the update of the collision groups(even tho i didn’t mess around with this)

its just 1 extra part and a weld that didn’t need if the collisions if they worked properly

Yeah, unless you have some code messing with collision groups then it’s entirely on ROBLOX.
Why you have such instability with collisions I have no clue.