I'm trying to make a voting mechanic for my game, but when I touch the part that counts the vote, nothing is added to the value and it stays as 0. (This is only a fragment of the code and the local is at the top of the script)
local Button = script.Parent Button.Touched:Connect(function() Button.VoteCount.Value = Button.VoteCount.Value + 1 end)
Is the something wrong with the touch function? Before anyone asks, I did try FindFirstChild and this is a server script.
I believe it isn't working because the game is FE. You could use remote events to get this to work.
-- LocalScript in Starter Player scripts local Button = game.Workspace.VotingCentre.Buttons.Button1 Button.Touched:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer() end)
-- Server Script in SererScriptService game.ReplicatedStrorage.RemoteEvent.OnServerEvent:Connect(function() Button.VoteCount.Value = Button.VoteCount.Value + 1 end)
You need to check that the hit is player
local Button = script.Parent Button.Touched:Connect(function(hit) --You can get the part that touch here if game.Players:GetPlayerFromCharacter(hit.Parent) then Button.VoteCount.Value = Button.VoteCount.Value + 1 end end)
But this will spam the vote count. So try add something to check if the player that hit hasn't been vote before.
I try to add folder.
local Button = script.Parent Button.Touched:Connect(function(hit) --You can get the part that touch here if game.Players:GetPlayerFromCharacter(hit.Parent) then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr.Character:FindFirstChild("VoteCheck") then else Button.VoteCount.Value = Button.VoteCount.Value + 1 local check = Instance.new("Folder",plr.Character) check.Name = "VoteCheck" end end end)