When i run a script with the following inside:
script.Parent.Triggered:Connect(function(player)
if player.Character.Money.Value > 499 then
local tool = ‘AR15’
if player.Character:FindFirstChild(tool) or player.Backpack:FindFirstChild(tool) then
if player.Character.Money.Value > 399 then
player.Character.Money.Value = player.Character.Money.Value - 400
local ammo = game.Lighting.Ammo.AR15.Magazine:Clone()
ammo.Parent = workspace
ammo.CFrame = script.Parent.Parent.Parent.MagSpawnPos.CFrame
end
else
if player.Character.Money.Value > 799 then
player.Character.Money.Value = player.Character.Money.Value - 800
local gun = game.Lighting.AR15:Clone()
gun.Parent = workspace
gun.Handle.CFrame = player.Character.Torso.CFrame + Vector3.new(0,2,0)
end
end
end
end)
This spawns a weapon or gives ammo depending on the circumstances. Some reason, the magazine adding script bugs out with no error, where it just access the AR15 inside of the player, and adds to a value that has sense gone down, how can i fix this. This is very annoying and makes no sense. Finaly, this is the adding script inside of the mag. it DOES add, but doesnt add from the number it is at at current time.
script.Parent.Triggered:Connect(function(part)
local person = part.Name
local workspaceper = workspace:FindFirstChild(person)
local ammo = workspaceper.AR15.TotalAmmo.Value
workspaceper.AR15.TotalAmmo.Value = workspaceper.AR15.TotalAmmo.Value + 25
print(ammo)
script.Parent.Parent:Destroy()
end)
Are the weapons and magazines meant to be placed in game.Lighting? I think it would be better if you would place them in ReplicatedStorage (or ServerStorage), unless you have a reason to keep them in game.Lighting.
For the ammo error, try making an IF statement to check if the ammo has reached to 0, then waits for the amount of time you want the gun to take to reload the gun.
Here is an example:
script.Parent.Triggered:Conect(function(player)
local character = player.Character
local ammo = character.AR15.TotalAmmo.Value
if ammo.Value == 0 then
wait() -- how many seconds you want it to add the value
ammo.Value += 25
print(ammo)
script.Parent.Parent:Destroy()
end
end)
just saw this, this isnt the problem, it just never registers the change of numbers. Like if i start with 25 in there, remove all of the 25 bullets then pick up the mag that has the += 25 in it it will become 50