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

Why is my local script inside of StarterGui not working?

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

Here is the script:

local ar = game.StarterGui.WeaponSelectorGUI.MainFrame.AssaultRifle
local cb = game.StarterGui.WeaponSelectorGUI.MainFrame.Crossbow
local gl = game.StarterGui.WeaponSelectorGUI.MainFrame.GrenadeLauncher
local pistol = game.StarterGui.WeaponSelectorGUI.MainFrame.Pistol
local rl = game.StarterGui.WeaponSelectorGUI.MainFrame.RocketLauncher
local smg = game.StarterGui.WeaponSelectorGUI.MainFrame.SMG
local shotgun = game.StarterGui.WeaponSelectorGUI.MainFrame.Shotgun
local sniper = game.StarterGui.WeaponSelectorGUI.MainFrame.Sniper
local turnFoward = game.StarterGui.WeaponSelectorGUI.MainFrame.TurnForward
local turnBack = game.StarterGui.WeaponSelectorGUI.MainFrame.TurnBack
game.ReplicatedStorage.RemoteEvents.RemoveCash.OnClientEvent:Connect(function()
	ar.Text = "weapon is currently unavailable"
	ar.Active = false
	cb.Text = "weapon is currently unavailable"
	cb.Active = false
	gl.Text = "weapon is currently unavailable"
	gl.Active = false
	pistol.Text = "weapon is currently unavailable"
	pistol.Active = false
	rl.Text = "weapon is currently unavailable"
	rl.Active = false
	smg.Text = "weapon is currently unavailable"
	smg.Active = false
	shotgun.Text = "weapon is currently unavailable"
	shotgun.Active = false
	sniper.Text = "weapon is currently unavailable"
	sniper.Active = false
	turnFoward.Text = "this button is currently unavailable"
	turnFoward.Active = false
	turnBack.Text = "this button is currently unavailable"
	turnBack.Active = false
	wait(300)
	ar.Text = "Assault Rifle"
	ar.Active = true
	cb.Text = "Crossbow"
	cb.Active = true
	gl.Text = "Grendade Launcher"
	gl.Active = true
	pistol.Text = "Pistol"
	pistol.Active = true
	rl.Text = "Rocket Launcher"
	rl.Active = true
	smg.Text = "SMG"
	smg.Active = true
	shotgun.Text = "Shotgun"
	shotgun.Active = true
	sniper.Text = "Sniper"
	sniper.Active = true
	turnFoward.Text = "Turn Forward"
	turnFoward.Active = true
	turnBack.Text = "Turn Back"
	turnBack.Active = true
end)

updated code:

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local ar = PlayerGui.WeaponSelectorGUI.MainFrame.AssaultRifle
local cb = PlayerGui.WeaponSelectorGUI.MainFrame.Crossbow
local gl = PlayerGui.WeaponSelectorGUI.MainFrame.GrenadeLauncher
local pistol = PlayerGui.WeaponSelectorGUI.MainFrame.Pistol
local rl = PlayerGui.WeaponSelectorGUI.MainFrame.RocketLauncher
local smg = PlayerGui.WeaponSelectorGUI.MainFrame.SMG
local shotgun = PlayerGui.WeaponSelectorGUI.MainFrame.Shotgun
local sniper = PlayerGui.WeaponSelectorGUI.MainFrame.Sniper
local turnFoward = PlayerGui.WeaponSelectorGUI.MainFrame.TurnForward
local turnBack = PlayerGui.WeaponSelectorGUI.MainFrame.TurnBack

game.ReplicatedStorage.RemoteEvents.RemoveCash.OnClientEvent:Connect(function()
	ar.Text = "weapon is currently unavailable"
	ar.Active = false
	cb.Text = "weapon is currently unavailable"
	cb.Active = false
	gl.Text = "weapon is currently unavailable"
	gl.Active = false
	pistol.Text = "weapon is currently unavailable"
	pistol.Active = false
	rl.Text = "weapon is currently unavailable"
	rl.Active = false
	smg.Text = "weapon is currently unavailable"
	smg.Active = false
	shotgun.Text = "weapon is currently unavailable"
	shotgun.Active = false
	sniper.Text = "weapon is currently unavailable"
	sniper.Active = false
	turnFoward.Text = "this button is currently unavailable"
	turnFoward.Active = false
	turnBack.Text = "this button is currently unavailable"
	turnBack.Active = false
	wait(300)
	ar.Text = "Assault Rifle"
	ar.Active = true
	cb.Text = "Crossbow"
	cb.Active = true
	gl.Text = "Grendade Launcher"
	gl.Active = true
	pistol.Text = "Pistol"
	pistol.Active = true
	rl.Text = "Rocket Launcher"
	rl.Active = true
	smg.Text = "SMG"
	smg.Active = true
	shotgun.Text = "Shotgun"
	shotgun.Active = true
	sniper.Text = "Sniper"
	sniper.Active = true
	turnFoward.Text = "Turn Forward"
	turnFoward.Active = true
	turnBack.Text = "Turn Back"
	turnBack.Active = true
end)

2 answers

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

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:

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
PlayerGui.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.

4 comments

0

I was trying to make it so everyones Gui will change, will this still work for everyone?

0

@ieatbaconflakesdaily it will. using a localscript will change everyone's gui if you do it like that

0

still doesnt work.

0

ill update the code so you can see it.

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