How would I go about making a value only change once per player?

Basically, I want to make a vote sort-of system, so I made a part that changes the “vote” value each time it’s touched. Issue is, though, I couldn’t find a way to make it so the value only changes once per player, so I opted to simply destroy the script. My current plan with this is basically to (attempt) make some sort of horrible mess and amalgamation of localscripts and remoteevents to get this to work(I’m currently using a normal script)
Anyways, enough rambling, this is the current script:


Any suggestion for how I could achieve my goal with this script is greatly appreciated!

1 Like

Use can use remoteEcent with debounce :slight_smile:
Once a player touch the Part, set the Debounce to false and Fire the Remote Server to event.

Why not just a server script that puts the player inside a table when they touch it for the first time and check if that player is in the table before doing anything?

local playersTouched = {}

function onTouch(part)
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
	if player then
		if playersTouched[player] then --// check if the player touched the part
			return --// if the player touched the part already then stop
		end
		
		playersTouched[player] = true --// add the player to the table

		local vote = workspace.Value --// use workspace its the same as game.Workspace but makes your code look nicer.
		vote.Value = vote.Value + 1 --// you could also do vote.Value += 1 which is the same but again makes your code look nicer
	end
end

Once you’re done with the voting you can just do table.clear(playersTouched)

2 Likes

I’ve tried your script, but it doesn’t seem to work. The value simply does not change. I’m quite a beginner, so please do ignore any monkey-brain moments on my part.

Their script looks fine, you’ll need to remember to create the .Touched connection though.

script.Parent.Touched:Connect(onTouch)

Check the console for any errors & add calls to print() inside the function to debug.

Thanks. I kinda forgot about having to do that stuff at the end of a function.