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 3 years ago
Edited 3 years ago

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

Log in to vote
1
Answered by 3 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
3 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:

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.

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

Answer this question