Brick Color Change Client Side?

It’s already like that… This is the new version

local Checkpoints = game.Workspace.Game.Obby.Checkpoints
local Debounce = false
local Players = game:GetService("Players").LocalPlayer

for index, value in pairs(Checkpoints:GetChildren()) do
	if value.Touched:Connect(function(part)
			--StageEvent:FireServer()
			local partParent = part.Parent
			local player = game.Players:GetPlayerFromCharacter(partParent)
			local leaderstats = player.leaderstats
			local playerStage = leaderstats.Stage
			local playerPoints = leaderstats.Points
			if tonumber(value.Name) == playerStage.Value + 1 then
				if not Debounce then
					Debounce = true
					print("WHAT IS THIS SORCERY?")
					--value.BrickColor = BrickColor.new(0,255,0)
					playerStage.Value = playerStage.Value + 1
					playerPoints.Value = playerPoints.Value + 5
					wait()
					Debounce = false
					if part:IsDescendantOf(player.Character) then
						value.BrickColor = BrickColor.new(0,255,0)
					end
					if player.MembershipType == Enum.MembershipType.Premium then
						print("Premium you get +5 points!")
						-- Take some action specifically for Premium members
						playerPoints.Value = playerPoints.Value + 5
					else
						print("Non premium you just get + 5")
					end
				end
			end
		end) then
	end
end

im talking about that, if its only meant to be clientsided than that shouldnt be there and should only refer to

Just check if the userid of the player that touches the checkpoint is the same as the local player’s userid.

Thank you works just how I want it to!
I was using localplayer for leaderstats earlier lol then realized why it wasn’t working properly. I seperated both now thanks again!

1 Like

I know you already found your solution but yeah I was about to say that I modified your code for desired results.

clientresults2


This is the adapted code I used (in a localscript, under StarterPlayerScripts):

local Checkpoints = game.Workspace.Checkpoints
local Debounce = false

for index, value in pairs(Checkpoints:GetChildren()) do
	if value.Touched:Connect(function(part)
			local partParent = part.Parent
			local player = game.Players:GetPlayerFromCharacter(partParent)
			local leaderstats = player.leaderstats
			local playerStage = leaderstats.Stage
			local playerPoints = leaderstats.Points
			if tonumber(value.Name) == playerStage.Value + 1 then
				if not Debounce then
					Debounce = true
					print("Working checkpoint!")
					--value.BrickColor = BrickColor.new(0,255,0)
					playerStage.Value = playerStage.Value + 1
					playerPoints.Value = playerPoints.Value + 5
					wait()
					Debounce = false
					if player and part:IsDescendantOf(game.Players.LocalPlayer.Character) then
						value.BrickColor = BrickColor.new(0,255,0)
					end
					if player.MembershipType == Enum.MembershipType.Premium then
						print("Premium you get +5 points!")
						-- Take some action specifically for Premium members
						playerPoints.Value = playerPoints.Value + 5
					else
						print("Non premium you just get + 5")
					end
				end
			end
		end) then
	end
end

2 Likes

Awesome thank you for your help!

value.BrickColor here seems incorrect.

1 Like