-
What do you want to achieve?
Create an “Ammo” system with my grenades. -
What is the issue?
The “CurrentAmmo” IntValue Isn’t Subtracting. -
What solutions have you tried so far?
- Changing the name of the value and folder.
- Using a function to subtract and add ammo.
- Modifying the script in different ways to see if it would work.
-
What was the solution to the problem?
Needed to change theCurrentAmmo
Variable Toscript.Parent.Storage.Configuration.CurrentAmmo
fromscript.Parent.Storage.Configuration.CurrentAmmo.Value
.
Screenshots
The Grenade Tool:
The “Storage” Folder:
Code
The “Server” Script:
Tool = script.Parent
Remote = Tool:FindFirstChild("RemoteEvent")
Grenade = script:FindFirstChild("Grenade")
-- CurrentAmmo = script.Parent.Storage.Configuration.CurrentAmmo.Value --
CurrentAmmo = script.Parent.Storage.Configuration.CurrentAmmo
Grenade.Parent = nil
Debounce = false
function ModifyAmmo(Amount, Type)
if Type == "Add" then
-- CurrentAmmo += Amount --
CurrentAmmo.Value += Amount
elseif Type == "Subtract" then
-- CurrentAmmo -= Amount --
CurrentAmmo.Value -= Amount
else
warn("No Type Selected - Ammo")
end
end
Remote.OnServerEvent:Connect(function(Player)
-- if CurrentAmmo == 0 then --
if CurrentAmmo.Value == 0 then
Tool.Handle.Transparency = 1
elseif CurrentAmmo > 0 then
Tool.Handle.Transparency = 0
if Debounce == false then
Debounce = true
local Humanoid = Player.Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local ThrowAnimation = Instance.new("Animation")
ThrowAnimation.AnimationId = "rbxassetid://6543998754"
local ThrowAnimationTrack = Animator:LoadAnimation(ThrowAnimation)
ThrowAnimationTrack:Play()
ThrowAnimationTrack.Stopped:Connect(function()
ModifyAmmo(1, "Subtract")
local ClonedGrenade = Grenade:Clone()
ClonedGrenade.Parent = game:GetService("Workspace")
ClonedGrenade.Explosion.Disabled = false
ClonedGrenade.Position = Player.Character.RightHand.Position
ClonedGrenade.Velocity = Player.Character.UpperTorso.CFrame.lookVector * 100
wait(5)
Debounce = false
end)
end
else
warn("Unknown Error Occured - Ammo")
end
end)
The “Client” Script:
Tool = script.Parent
Player = game:GetService("Players").LocalPlayer
Remote = Tool:FindFirstChild("RemoteEvent")
GUI = Tool.Storage.GUI.GrenadeGUI
Tool.Equipped:Connect(function()
ClonedGUI = GUI:Clone()
ClonedGUI.Parent = Player.PlayerGui
end)
Tool.Unequipped:Connect(function()
ClonedGUI:Destroy()
end)
Tool.Activated:Connect(function()
Remote:FireServer(Player)
end)
Information
-
Everything works as it should except the “CurrentAmmo” IntValue, It doesn’t subtract.
-
When I change the IntValue manually in-game using the explorer, it changes the GUI and doesn’t allow me to throw the grenade (Works as it should)
-
There is no error in the output.
Any Help Appreciated!