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

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

Asked by
N43FGXL 169
5 years ago

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

Log in to vote
0
Answered by
B_rnz 171
5 years ago
Edited 5 years ago

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!

0
Now on line 17 I get a red underline under the end. N43FGXL 169 — 5y
0
add another end RobloxGameingStudios 145 — 5y
0
I get the error: expected (to close '(' at line 3) near 'end' || Adding another end doesn't work. N43FGXL 169 — 5y
0
Undoing what B_rnz did fixes it.. But I still get the first error. N43FGXL 169 — 5y
View all comments (2 more)
0
Original Error: gamestatusv is not a valid member of DataModel N43FGXL 169 — 5y
0
I'll edit it, wait... B_rnz 171 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Answer this question