I created a shop that sold guns, and it all worked fine. The thing is, when the player dies, they lose all the guns that they bought, and only the starter gun remains in their inventory.
Here's my LocalScript inside of one of the guns:
game.Players.LocalPlayer.Backpack.ChildAdded:Connect(function()
local MaxAmmo = 40
local Ammo = MaxAmmo
local character = game.Players.LocalPlayer.Character
local function createBullet()
local bulletPart = workspace.bullet:Clone()
bulletPart.Parent = workspace
bulletPart.Position = script.Parent.Handle.Part.Position
bulletPart.Orientation = bulletPart.Orientation + (script.Parent.Handle.Orientation - Vector3.new(0,90,0))
for i = 0,25,10 do
bulletPart.CFrame = bulletPart.CFrame * CFrame.new(0,0,i)
wait()
end
bulletPart:remove()
end
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
while not character do
character.AncestryChanged:Wait()
end
local hum = character:WaitForChild('Humanoid')
local reloadAnim = hum:LoadAnimation(script.Parent.Animation)
local fireAnim = hum:LoadAnimation(script.Parent.fire)
script.Parent:WaitForChild('MaxAmmo').Value = MaxAmmo
script.Parent:WaitForChild('Ammo').Value = Ammo
local canDamage = true
local Reloading = false
local uis = game:GetService("UserInputService")
script.Parent.Equipped:Connect(function()
uis.MouseIconEnabled = true
game.Players.LocalPlayer:GetMouse().Icon = 'rbxassetid://68308747'
end)
script.Parent.Unequipped:Connect(function()
uis.MouseIconEnabled = false
game.Players.LocalPlayer:GetMouse().Icon = 'rbxassetid://442141180'
end)
local canFire = true
local isDamaging = false
script.Parent.Activated:Connect(function()
canFire = true
if Ammo > 0 and not Reloading then
while canFire == true do
isDamaging = true
script.Parent.Handle.fire:Play()
fireAnim:Play()
Ammo = Ammo - 1
script.Parent.Handle.BillboardGui.Frame.TextLabel.Text = Ammo.." / "..MaxAmmo
script.Parent.Handle.Part.FrontFlash.Transparency = 0
script.Parent.Handle.Part.BackFlash.Transparency = 0
wait()
script.Parent.Handle.Part.FrontFlash.Transparency = 1
script.Parent.Handle.Part.BackFlash.Transparency = 1
createBullet()
if Ammo <= 0 then
canFire = false
end
end
while true do
if isDamaging == true then
game.Players.LocalPlayer:GetMouse().Target.Parent:WaitForChild('EnemyHum'):TakeDamage(6)
end
wait(.1)
end
elseif Reloading == false then
uis.InputBegan:Connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.R then
if Reloading == false then
if Ammo <= 0 then
reloadAnim:Play()
Reloading = true
script.Parent.Handle.reload:Play()
wait(script.Parent.Handle.reload.TimeLength)
script.Parent.Handle.BillboardGui.Frame.TextLabel.Text = "40 / 40"
Ammo = MaxAmmo
Reloading = false
end
end
end
end)
end
end)
script.Parent.Unequipped:Connect(function()
isDamaging = false
canDamage = false
canFire = false
Reloading = false
script.Parent.Handle.reload:Stop()
reloadAnim:Stop()
end)
script.Parent.Deactivated:Connect(function()
isDamaging = false
canFire = false
end)
end)
Yes, this is long and I'm very sorry for that. I really need answers though, because I want this game out as soon as possible.
**

1 comment
do you have a core script for players? just wondering because my method involves cloning the players tools when they die, temporarly store them in a seperate folder, then when the character loads, I take those cloned tools and replace them in the backpack.