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

How exactly do I add to a value?

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.

2 comments

0

Where is the Button located

0

game.Workspace.VotingCentre.Buttons.Button1

3 answers

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)

1 comment

0

That isn't working either

I fixed it by repositioning the Touched event in the script oof

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)

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