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

Trying to make gui appear and disappear when variable is changed. I get an error. Fix?

So I am making a GUI for my game with rounds that has a GUI that is supposed to change when a variable (gamestatusv) is changed to 1 or 2. 1 is for on and 2 is for off.

local gamestatusv = game.ReplicatedStorage:WaitForChild("GameStatus") ---- Location of IntValue in game.
game.gamestatusv.Changed:connect(function() --Function
	if game.gamestatusv.Value == "1" then
		game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Backs.Visible = true --On
		game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Heads.Visible = true
		game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Tails.Visible = true
		game.Players.LocalPlayer.PlayerGui.TimerGui.Timer.Visible = true
			
		else if gamestatusv.Value == "2" then
			game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Backs.Visible = false --Off
			game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Heads.Visible = false
			game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Tails.Visible = false
			game.Players.LocalPlayer.PlayerGui.TimerGui.Timer.Visible = false
		
		end
	end
end)

I get the error: "gamestatusv is not a valid member of datamodel" . I am confused and really stuck. How do I fix this? I can provide the location of things if you need me to.

2 answers

Because you're not using 'elseif' but 'else if'

And also, you're getting gamestatusv, and not the instance 'gamestatusv'

So if I am right your script should look something like:

local gamestatusv = game.ReplicatedStorage:WaitForChild("GameStatus") 

game.gamestatusv.Changed:connect(function() 
    if game.gamestatusv.Value == "1" then
        game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Backs.Visible = true 
        game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Heads.Visible = true
        game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Tails.Visible = true
        game.Players.LocalPlayer.PlayerGui.TimerGui.Timer.Visible = true

    elseif game.gamestatusv.Value == "2" then -- where you went wrong.
        game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Backs.Visible = false 
        game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Heads.Visible = false
        game.Players.LocalPlayer.PlayerGui.CoinGuessGui.Tails.Visible = false
        game.Players.LocalPlayer.PlayerGui.TimerGui.Timer.Visible = false
        end
    end
end)

Hope this works!

6 comments

0

Now on line 17 I get a red underline under the end.

0

add another end

0

I get the error: expected (to close '(' at line 3) near 'end' || Adding another end doesn't work.

0

Undoing what B_rnz did fixes it.. But I still get the first error.

0

Original Error: gamestatusv is not a valid member of DataModel

0

I'll edit it, wait...

Line 2 of your script you're calling for game.gamestatusv. So the game is reading that as:

game.game.ReplicatedStorage:WaitForChild("GameStatus").Changed:Connect(function()

Change it to:

gamestatusv.Changed:Connect(function()

This should work.

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