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)
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