I am creating a cannon tool, and I would like for the textlabel’s text to change whenever the ammo NumberValue changes, which will happen when the player fires the weapon.
For some reason, the text simply does not change. The localscript can read the value (it’s being set serverside), and I know this because it works correctly when it does the same thing except when unequipping and then reequipping the tool. Though when I attempt to do it mid-script, it doesn’t do anything.
There are no errors in the console, and I have tried every alternative way I can think of, yet it still doesn’t work.
Script (I have marked the part that doesn’t work in a code comment):
local Players = game:GetService("Players")
local holding = false
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:Wait()
end
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local ToolAnimation = Instance.new("Animation")
ToolAnimation.AnimationId = "rbxassetid://9157515489"
local ToolAnimationTrack = animator:LoadAnimation(ToolAnimation)
local Cooldown = false
script.Parent.Activated:Connect(function()
local ammo = script.Parent.Ammo.Value
if Cooldown == false and ammo > 0 then
Cooldown = true
ToolAnimationTrack:Play()
--the problem occurs here
local uitext = game.Players.LocalPlayer.PlayerGui:FindFirstChild("AmmoGui").Frame.Ammo.Text
uitext = ammo - 1
wait(5)
Cooldown = false
end
end)
script.Parent.Equipped:Connect(function()
holding = true
local GuiClone = script.AmmoGui:Clone()
GuiClone.Parent = player.PlayerGui
local ammo = script.Parent.Ammo.Value
GuiClone.Frame.Ammo.Text = ammo
end)
script.Parent.Unequipped:connect(function()
holding = false
ToolAnimationTrack:Stop()
game.Players.LocalPlayer.PlayerGui:FindFirstChild("AmmoGui"):Destroy()
end)
Any help or explanation to why this is happening would be much appreciated!