I want to make a map selection place where you can vote for maps.
When a player steps on the selection part, I would like the part to go green for only that player who voted on that map. The problem is that when I do it through a local script, it doesn’t work?
I have tried using events and have tried to find any articles that could help.
Note, my scripting skills aren’t great and I may not understand any more advanced code
local touched = true -- Variable to toggle between color sets
script.Parent.Touched:Connect(function(hit)
if 0 == 1 then
script.Parent.Color = Color3.new(0, 1, 0.177768)
script.Parent.Highlight.FillColor = Color3.new(0, 1, 0.177768)
script.Parent.Highlight.OutlineColor = Color3.new(0, 0.500008, 0.0916609)
end
touched = not touched -- Toggle the variable
local value = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.Events.ChoseMap:FireClient(value)
end)
Try printing value, it could be that it isn’t a Player, I’d expect it to show an error but we could try anyway. If it still doesn’t print anything that means the Touched event isn’t firing.
Can you show me what the explorer looks like for the buttons and their scripts? Also with a setup like this I think it’d be better to check for collisions on the client, and fire a remote event to the server, of course checking it isn’t anything malicious or invalid.
Imo, you should make the color change and voting separate.
Let one local script listen for any .touched events with the three voting parts. Whenever one is fired, check if it’s the character of the local player and if so, then change the part color. Whenever you change the color, also listen for a new Touch Ended event with that specific part. When this one is fired, if it’s the character, you revert the color change and disconnect the event.