How do I change part properties (such as color) with a local script?

I want to make a map selection place where you can vote for maps.

  1. 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?

  2. 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

This is the local script:

game.ReplicatedStorage.Events.ChoseMap.OnClientEvent:Connect(function()
	print('hi')
	script.Parent.Color = Color3.new(0, 1, 0.177768)
	script.Parent.Highlight.FillColor = Color

3.new(0, 1, 0.177768)
	script.Parent.Highlight.OutlineColor = Color3.new(0, 0.500008, 0.0916609)
end)

Were there any errors in console/output, and does it print “hi”? Also, I’d suggest using Color3.fromRGB() (for your own sanity)

Nope, at least not any related to the issue, also it didn’t print the hi part

1 Like

What’s the server code that fires this game.ReplicatedStorage.Events.ChoseMap? It’s very likely that it just isn’t running at all.

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)
1 Like

half of the code is useless, but the bottom part is more important

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.

Nope, I tried and nothing happened

1 Like

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.

1 Like

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.

2 Likes

I will try this idea, I think it should work

This actually worked, thank you so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.