I am trying to make this gun magazine drop out when reloading. sense i have no clue on how to do that i am trying to model off of other scripts, now that is not working out correctly, that left me only one option that is to ask for help.

This script is not mine but i am trying to model off of scripts like this to make my own. its is very long i really would appreciate this, if it works i will make give the person the model i had to trim the script becuase of its lenth.

-- Made by Stickmasterluke
 -- edited by fusroblox
local GoreOn=true
function WaitForChild(parent,child)
	while not parent:FindFirstChild(child) do print("2waiting for " .. child) wait() end
	return parent[child]
end
 
local GunObject = {
	Tool = script.Parent,
	Handle = WaitForChild(script.Parent,'Handle'),
	check = true,
	
	GunDamage = 27, -- Base output damage per shot.
	FireRate = .1, -- How often the weapon can fire.
	Automatic = true, -- hold down to continue firing
	Range = 250, -- Max distance that the weapon can fire.
	Spread = 1, -- The bigger the spread, the more inaccurate the shots will be.
	ClipSize = 30, -- Shots in a clip
	ReloadTime = 0, -- Time it takes to reload the tool.
	StartingClips = 10, -- If you want infinit clips, remove the IntValue named "Clips" from the tool.
	SegmentLength = 40, -- How long the shot segments are, or the speed of the shot.
	FadeDelayTime = 1/30,
	
	
	BarrelPos = CFrame.new(0, 0, - 1.2), -- L, F, U
	Rate = 1/30,
	--local Colors = {BrickColor.new("Bright red"), BrickColor.new("Really red"), BrickColor.new("Dusty Rose"), BrickColor.new("Medium red")}
	Colors = {BrickColor.new("Bright yellow"),BrickColor.new("Mid gray"), BrickColor.new("Medium stone grey"), BrickColor.new("Dark stone grey")},
	FlashColors = {"Medium red", "Dusty Rose", "Bright red", "Really red"},
	
	Reloading = false,
	Debris = game:GetService("Debris"),
	Ammo,
	Clips,
	LaserObj,
	SparkEffect,
	ShellPart,
	--tool children
	DownVal=WaitForChild(script.Parent, 'Down'),
	AimVal=WaitForChild(script.Parent, 'Aim'),
	ReloadingVal=WaitForChild(script.Parent, 'Reloading'),
	DoFireAni = WaitForChild(script.Parent,'DoFireAni'),
	
	--handlechildren
	Fire,
	
}

--[[Member functions]]

function GunObject:Initialize()

	self.Fire=WaitForChild(self.Handle, 'Fire')
	
	self.Ammo = self.Tool:FindFirstChild("Ammo")
	if self.Ammo ~= nil then
		self.Ammo.Value = self.ClipSize
	end
	self.Clips = self.Tool:FindFirstChild("Clips")
	if self.Clips ~= nil then
		self.Clips.Value = self.StartingClips
	end
	self.Tool.Equipped:connect(function()
		self.Tool.Handle.Fire:Stop()
		self.Tool.Handle.Reload:Stop()
	end)
	self.Tool.Unequipped:connect(function()
		self.Tool.Handle.Fire:Stop()
		self.Tool.Handle.Reload:Stop()
	end)
	self.LaserObj = Instance.new("Part")
	self.LaserObj.Name = "Bullet"
	self.LaserObj.Anchored = true
	self.LaserObj.CanCollide = false
	self.LaserObj.Shape = "Block"
	self.LaserObj.formFactor = "Custom"
	self.LaserObj.Material = Enum.Material.Neon
	self.LaserObj.Locked = true
	self.LaserObj.TopSurface = 0
	self.LaserObj.BottomSurface = 0

	local tSparkEffect = Instance.new("Part")
	tSparkEffect.Name = "Effect"
	tSparkEffect.Anchored = false
	tSparkEffect.CanCollide = false
	tSparkEffect.Shape = "Block"
	tSparkEffect.formFactor = "Custom"
	tSparkEffect.Material = Enum.Material.Neon
	tSparkEffect.Locked = true
	tSparkEffect.TopSurface = 0
	tSparkEffect.BottomSurface = 0
	self.SparkEffect=tSparkEffect

	local tshell = Instance.new('Part')
	tshell.Name='effect'
	tshell.FormFactor='Custom'
	tshell.Size=Vector3.new(1, 0.4, 0.33)
	tshell.BrickColor=BrickColor.new('Bright yellow')
	local tshellmesh=WaitForChild(script.Parent,'BulletMesh'):Clone()
	tshellmesh.Parent=tshell
	self.ShellPart = tshell

	self.DownVal.Changed:connect(function()
		while self.DownVal.Value and self.check and not self.Reloading do
			self.check = false
			local humanoid = self.Tool.Parent:FindFirstChild("Humanoid")
			local plr1 = game.Players:GetPlayerFromCharacter(self.Tool.Parent)
			if humanoid ~= nil and plr1 ~= nil then
				if humanoid.Health > 0 then
					local spos1 = (self.Tool.Handle.CFrame * self.BarrelPos).p
					delay(0, function() self:SendBullet(spos1, self.AimVal.Value, self.Spread, self.SegmentLength, self.Tool.Parent, self.Colors[1], self.GunDamage, self.FadeDelayTime) end)
				else
					self.check = true
					break
				end
			else
				self.check = true
				break
			end
			wait(self.FireRate)
			self.check = true
			if not self.Automatic then
				break
			end
		end
	end)

	self.ReloadingVal.Changed:connect(function() if self.ReloadingVal.Value then self:Reload() end end)

end



function GunObject:Reload()
	self.Reloading = true
	self.ReloadingVal.Value = true
	if self.Clips ~= nil then
		if self.Clips.Value > 0 then
			self.Clips.Value = Clips.Value - 1
		else
			self.Reloading = false
			self.ReloadingVal.Value = false
			return
		end
	end
	self.Tool.Handle.Reload:Play()
	for i = 1, self.ClipSize do
		wait(self.ReloadTime/self.ClipSize)
		self.Ammo.Value = i
	end
	self.Reloading = false
	self.Tool.Reloading.Value = false
end



function GunObject:SpawnShell()
	local tshell=self.ShellPart:Clone()
	tshell.CFrame=self.Handle.CFrame
	tshell.Parent=Workspace
	game.Debris:AddItem(tshell,2)
end

function KnockOffHats(tchar)
	for _,i in pairs(tchar:GetChildren()) do
		if i:IsA('Hat') then
			i.Parent=game.Workspace
		end
	end
end

2 comments

0

It is best if what you use is your own work, then you understand it and can easily fix mistakes - Jo_Bot That's going to go in my quote book! :P

0

but how am i going to use my own work, if i dont know how to create my own work, thats the point of me comming here.