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

How do I access setting in player?

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)

1 comment

0

I got some of this code from a vip door, so that's why its like that

1 answer

✓ Accepted answer

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)

1 comment

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.

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