I am scripting a SubMachineGun. First I have these values inside of Replicated Storage: SMGAmmoLeft, The ammo left in the SMG SMGEquipped, Whether the SMG is equipped. I also have a Remote Event called FiringSMGEvent. I have this Local Script inside of a gun tool in Starter Pack.
local gun = scriptt.Parent local ReplicatedStorage = game:GetService('ReplicatedStorage') local remoteEvent = ReplicatedStorage:WaitForChild('FiringSniperEvent') local shooting = false local equipped = false local EquipValue = ReplicatedStorage.EquippedSMG.Value EquipValue=false local player = game.Players.LocalPlayer local mouse = player:GetMouse() local mouseConnection gun.Equipped:Connect(function() equipped = true EquipValue=true mouse.Icon = 'rbxassetid://117431027' mouseConnection = mouse.Button1Down:Connect(function() shooting = true while shooting and equipped do remoteEvent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p) gun.Ammo.Value-=1 game.ReplicatedStorage.SMGAmmo.Value-=1 if gun.Ammo.Value==0 then equipped=false game.ReplicatedStorage.SMGAmmo.Value=0 wait(5) gun.Ammo.Value=50 game.ReplicatedStorage.SMGAmmo.Value=50 equipped=true end mouse.Button1Up:Connect(function() shooting = false end) wait(0.1) end end) end) gun.Unequipped:Connect(function() equipped = false mouseConnection:Disconnect() end)
I have this Local Script inside of a ScreenGui which is home to a TextLabel which is supposed to display the ammo left.
script.Parent.TextLabel.Visible=false game.ReplicatedStorage.EquippedSMG.Changed:Connect(function() if game.ReplicatedStorage.EquippedSMG == true then script.Parent.TextLabel.Visible=true script.Parent.TextLabel.Text = game.ReplicatedStorage.SMGAmmo.Value elseif game.ReplicatedStorage.EquippedSMG == false then script.Parent.TextLabel.Visible=false end end)
The TextLabel is not displaying the AmmoLeft. May you please help me?