-
What do you want to achieve? Keep it simple and clear!
I want this script to properly add numbers to existing Value! -
What is the issue? Include screenshots / videos if possible!
My player spawns with 50 Ammo, after a while, my ammo goes all the way to 35.6. Then I trigger proximity. You would expect number to change to 40.6 ammo. Suprise, it goes all the way to 55, even tho the script should add only 5 Ammo. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Youtube, AI, Forums. Nothing really that explains the problem I have. Or I dont really look deeply enough.
I do believe that script is somehow fetching from the leaderstats, where I gave player starting amount of Ammo and completely ignores the changing value. I am not in all means a great scripter.
Thank you in advance for your Ideas!
Script that rewards player with Ammo:
local CC = game:GetService("CollectionService")
local SS = game:GetService("ServerStorage")
local function SetFunc(TaggedPart)
local Machine = TaggedPart
local ProximityPrompt = Machine:WaitForChild("GetAmmo").ProximityPrompt
local Sound = Machine:WaitForChild("GetAmmo").AmmoPickup
ProximityPrompt.Triggered:connect(function(Player)
if Player and Player.Character and Player.leaderstats:FindFirstChild("Scraps").Value >= 5
and Player.leaderstats:FindFirstChild("Ammo").Value < 100 then
ProximityPrompt.Enabled = false
Player.leaderstats.Scraps.Value = Player.leaderstats.Scraps.Value - 5
task.wait(1)
Player.leaderstats.Ammo.Value = Player.leaderstats.Ammo.Value + 5
task.wait(1)
ProximityPrompt.Enabled = true
else
print("NO")
end
end)
end
-- Apply to already tagged Stalkers
for _, TaggedPart in pairs(CC:GetTagged("AmmoRefill")) do
SetFunc(TaggedPart)
end
-- Listen for newly tagged Stalkers
CC:GetInstanceAddedSignal("AmmoRefill"):Connect(SetFunc)
Leaderstat that I use:
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
local Ammo = Instance.new("NumberValue")
Ammo.Name = "Ammo"
Ammo.Value = 30
Ammo.Parent = stats
local Scraps = Instance.new("IntValue")
Scraps.Name = "Scraps"
Scraps.Value = 40
Scraps.Parent = stats
end)