I created a part with a touch event for a voting system, keep in mind I’m using Touched and not TouchEnded, but the event only fires after I stop stepping on the part.
Here’s the script:
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if game.Workspace.MatchState.Value == "GamemodeVoting" then
if game.Workspace.ScriptChoices.RGamemodes.Option2.Voters:FindFirstChild(plr.Name) then
game.Workspace.ScriptChoices.RGamemodes.Option2.Voters[plr.Name]:Destroy()
end
if not game.Workspace.ScriptChoices.RGamemodes.Option1.Voters:FindFirstChild(plr.Name) then
local sv = Instance.new("StringValue")
sv.Name = plr.Name
sv.Parent = game.Workspace.ScriptChoices.RGamemodes.Option1.Voters
end
elseif game.Workspace.MatchState.Value == "TeamVoting" then
if game.Workspace.ScriptChoices.RTeamsmodes.Option2.Voters:FindFirstChild(plr.Name) then
game.Workspace.ScriptChoices.RTeamsmodes.Option2.Voters[plr.Name]:Destroy()
end
if not game.Workspace.ScriptChoices.RTeamsmodes.Option1.Voters:FindFirstChild(plr.Name) then
local sv = Instance.new("StringValue")
sv.Name = plr.Name
sv.Parent = game.Workspace.ScriptChoices.RTeamsmodes.Option1.Voters
end
end
end
end)