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

How do I make a voting system with pads?

Asked by 5 years ago

What I am trying to do is set a 'HasVoted' bool value to true inside the 'settings' folder in the player if he votes for a game by touching a brick, then set a number value up one inside a workspace part, to count the vote. I'm not sure if I should use remote events for this part, can I get some help? I've already tried remote events to fire a client event in ReplicatedStorage, then get that event inside a local script, but that did not work :/

This adds the settings folder to the player:

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

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

This is actually quite easy to correct. There is no reason to fire an event, as the server can access the players. All you would need to do is connect a touched event to the voting pad:

I'm not sure how advanced you are so I'm going to try and explain everything.

script.Parent.Touched:Connect(function() -- This will run every time something hits the part.
    --script here
end)

Then you would need to check if it is a player, and if so, check if they have voted.:

script.Parent.Touched:Connect(function(hit) 
    if hit.Parent:FindFirstChild("Humanoid") then
        if game.Players:GetPlayerFromCharacter(hit.Parent).Settings.HasVoted ~= true then
            --Add votes and change BoolValue
        end
    end
end)

--Now just add the vote and make sure you change the BoolValue.

script.Parent.Touched:Connect(function(hit) --we've added a variable in the parentheses, the variable will be containing the part that touched the brick.
    if hit.Parent:FindFirstChild("Humanoid") then -- the reason we use hit.Parent is because the part that touches it would be the left or right leg, we need the character itself.
        if game.Players:GetPlayerFromCharacter(hit.Parent).Settings.HasVoted ~= true then -- ':GetPlayerFromCharacter()' is the function used to do exactly what it sounds like
            game.Players:GetPlayerFromCharacter(hit.Parent).Settings.HasVoted = true -- we set this before changing the value of the votes that way it can't run too fast and vote more than once before the value changes.
            -- change the value of votes in the appropriate IntValue    
        end
    end
end)

Hope I helped!

-Cmgtotalyawesome

0
That is completely wrong...... User#24403 69 — 5y
0
@sjr04Alt actually you're completely wrong, this way would work easily. cmgtotalyawesome 1418 — 5y
0
thanks! it works swell! TheGreenSuperman 85 — 5y
Ad

Answer this question