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

How do I access setting in player?

Asked by
Nickelz 37
6 years ago
Edited 6 years ago

when a player joins the game the game inserts a folder with a bool value: "hasvoted",

game.Players.PlayerAdded:connect(function(player)
    local settings = Instance.new("Folder",player)
    settings.Name = "Settings"
    local afk = Instance.new("BoolValue",settings)
    afk.Name = "hasvoted"
end)

now, whenever a player touches a part (to vote) how to I access this to check if he has or has not? this is my code so far, but it does not work:

script.Parent.Touched:connect(function(p)
    if game.Players:GetPlayerFromCharacter(p.Parent) then
        local player = game.Players:GetPlayerFromCharacter(p.Parent)
    if player.Settings.hasvoted == false then
        print("Player Voted.")
    elseif player.Settings.hasvoted == true then

        reply.Text = "You have already voted for an event!"
    end
    end


end)
0
I got some of this code from a vip door, so that's why its like that Nickelz 37 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You're comparing the object hasvoted with a bool value, but you're wanting to compare its value to it.

script.Parent.Touched:connect(function(p)
    if game.Players:GetPlayerFromCharacter(p.Parent) then
        local player = game.Players:GetPlayerFromCharacter(p.Parent)
    if player.Settings.hasvoted.Value == false then
        print("Player Voted.")
    elseif player.Settings.hasvoted.Value == true then

        reply.Text = "You have already voted for an event!"
    end
    end


end)
0
Also keep in mind your "p" variable refers to the brick that touched the script's Parent, which doesn't necessarily belongs to a player's Character. Consider revising line 2. Le_Teapots 913 — 6y
Ad

Answer this question