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

Changing a boolian in the player?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

So I have the boolian called "AFK" in the player (game.Players.AFK) and I'm trying to make it change on click, it's a local script. I don't know what's wrong and nothing is producing errors.

local plr = game.Players.LocalPlayer

function Down()
if plr.AFK.Value == true then
    plr.AFK.Value = true
script.Parent.Text = "Back"
else
    script.Parent.Text = "Go afk"
plr.AFK.Value = false
end
end

script.Parent.MouseButton1Click:connect(Down)

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

Your problem is your logic is backwards:

local plr = game.Players.LocalPlayer

function Down()
    if not plr.AFK.Value then --aka if plr.AFK.Value ~= true then
        plr.AFK.Value = true
        script.Parent.Text = "Back"
    else
            script.Parent.Text = "Go afk"
        plr.AFK.Value = false
    end
end

script.Parent.MouseButton1Click:connect(Down)

What the code was doing before was seeing that AFK.Value is true, and then setting it to true again!

0
thanks NotSoNorm 777 — 8y
Ad

Answer this question