Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I can not figure out why both UI elements show when only one should, maybe this is a bug in roblox?

So, I have two scripts, one in each item, and both are modified versions of the Pistol model from the Toolbox, designed to look more like a laser weapon, and it tells you how much ammo is left using a Gui element. I have the scripts functional, but for some reason, equipping just one of them causes both Labels to appear. I have them separate so the reloading text doesnt display when another weapon is equipped. So the Admin Version of the weapon makes both the Admin weapon's ui and the Normal weapon's ui appear/disappear, but it should only be making the Admin ui appear. Similar story for the normal version, it makes the admin ui appear.

Normal Version:

equipEvent.OnServerEvent:connect(function(player)
	player.Character.Humanoid.AutoRotate = false
	player.PlayerGui.WeaponsUI.AmmoPistol.Visible = true
	player.PlayerGui.WeaponsUI.AmmoPistol.Text = currentAmmo.."/"..clipSize
	plr = player
end)
unequipEvent.OnServerEvent:connect(function(player)
	player.Character.Humanoid.AutoRotate = true
	player.PlayerGui.WeaponsUI.AmmoPistol.Visible = false
end)

Admin Version:

equipEvent.OnServerEvent:connect(function(player)
	player.Character.Humanoid.AutoRotate = false
	player.PlayerGui.WeaponsUI.AmmoAdminPistol.Visible = true
	player.PlayerGui.WeaponsUI.AmmoAdminPistol.Text = currentAmmo.."/"..clipSize
	plr = player
end)
unequipEvent.OnServerEvent:connect(function(player)
	player.Character.Humanoid.AutoRotate = true
	player.PlayerGui.WeaponsUI.AmmoAdminPistol.Visible = false
end)

2 answers

✓ Accepted answer

local equipEvent = ?? and local unqeuipEvent ==??

If they're both listening to the same remote and there is nothing being passed which differentiates between which gun is being equiped then the script will run whenever any tool is equiped.

To fix this, maybe pass the name of the gun ...:Connect(function(player, weapon_name)...end) ... and check if the weapon_name == the name of the gun you are listening for if weapon_name == "the name of the weapon here, inside the speach marks" then ...... end

Now that I've checked the naming for the events created by the script, they do all have the same names for the same triggers. I'll have to change all that, but thanks for mentioning that. (Sometimes I overlook the simple stuff like names of objects.)

1 comment

0

No problem :) I think you should be able to just have one event and one listener script though rather than one for each gun, just pass the name of the item you're equiping and find the appropriate UI using the passed name too :)

This discussion is preserved as it was. New answers, comments, and votes are closed.