Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is my local script inside of StarterGui not working?

Asked by 4 years ago
Edited 4 years ago

Hi, I was wondering why my local script isn't working, I have put it inside of StarterGui.

Here is the script:

01local ar = game.StarterGui.WeaponSelectorGUI.MainFrame.AssaultRifle
02local cb = game.StarterGui.WeaponSelectorGUI.MainFrame.Crossbow
03local gl = game.StarterGui.WeaponSelectorGUI.MainFrame.GrenadeLauncher
04local pistol = game.StarterGui.WeaponSelectorGUI.MainFrame.Pistol
05local rl = game.StarterGui.WeaponSelectorGUI.MainFrame.RocketLauncher
06local smg = game.StarterGui.WeaponSelectorGUI.MainFrame.SMG
07local shotgun = game.StarterGui.WeaponSelectorGUI.MainFrame.Shotgun
08local sniper = game.StarterGui.WeaponSelectorGUI.MainFrame.Sniper
09local turnFoward = game.StarterGui.WeaponSelectorGUI.MainFrame.TurnForward
10local turnBack = game.StarterGui.WeaponSelectorGUI.MainFrame.TurnBack
11game.ReplicatedStorage.RemoteEvents.RemoveCash.OnClientEvent:Connect(function()
12    ar.Text = "weapon is currently unavailable"
13    ar.Active = false
14    cb.Text = "weapon is currently unavailable"
15    cb.Active = false
View all 53 lines...

updated code:

01local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
02 
03local ar = PlayerGui.WeaponSelectorGUI.MainFrame.AssaultRifle
04local cb = PlayerGui.WeaponSelectorGUI.MainFrame.Crossbow
05local gl = PlayerGui.WeaponSelectorGUI.MainFrame.GrenadeLauncher
06local pistol = PlayerGui.WeaponSelectorGUI.MainFrame.Pistol
07local rl = PlayerGui.WeaponSelectorGUI.MainFrame.RocketLauncher
08local smg = PlayerGui.WeaponSelectorGUI.MainFrame.SMG
09local shotgun = PlayerGui.WeaponSelectorGUI.MainFrame.Shotgun
10local sniper = PlayerGui.WeaponSelectorGUI.MainFrame.Sniper
11local turnFoward = PlayerGui.WeaponSelectorGUI.MainFrame.TurnForward
12local turnBack = PlayerGui.WeaponSelectorGUI.MainFrame.TurnBack
13 
14game.ReplicatedStorage.RemoteEvents.RemoveCash.OnClientEvent:Connect(function()
15    ar.Text = "weapon is currently unavailable"
View all 56 lines...

2 answers

Log in to vote
1
Answered by 4 years ago

It should work when the server FireClient() is fired or else check your output one of the variables might be not found

Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

You should use a LocalScript (Well you already did it, so no need to change.) and put it in game.StarterPlayer.StarterPlayerScripts. You must access the PlayerGui instead of StarterGui. Here's an example:

1local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
2PlayerGui.ScreenGui.TextLabel.Text = "Text!"

PRO TIP: Consider making a local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui") and replace ALL of the game.StarterGui text to PlayerGui.

If it still did not work. Consider marking this as an answer. I will try to help. Because I don't know your game content so I was just helping you the piece of code that I think it's the main problem.

0
I was trying to make it so everyones Gui will change, will this still work for everyone? ieatbaconflakesdaily 10 — 4y
0
@ieatbaconflakesdaily it will. using a localscript will change everyone's gui if you do it like that Xapelize 2658 — 4y
0
still doesnt work. ieatbaconflakesdaily 10 — 4y
0
ill update the code so you can see it. ieatbaconflakesdaily 10 — 4y

Answer this question