Brick Color Change Client Side?

Checkpoint system.

  • This code is basically supposed to change the character stage to the name of the checkpoint.
  • My problem is that the brickcolor change happens to all clients. I just want to it to happen to individual that touched the brick
  • The script is in starterchracterscripts. And it is a local script.
  • When I tested the game, I noticed that it does in fact change the checkpoint to green on client. And server still shows white. BUT every players checkpoint even if they haven’t gotten to it will change to green.
  • Everything else works fine. Will be adding checkpoint spawner after I figure this out.
    ~~ Client Side ~~

~~ Server Side ~~

CaptureServer

local Checkpoints = game.Workspace.Game.Obby.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 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

1 Like

Try moving it to StarterPlayerScripts instead, and see if it has any effect.

Same problem it doesn’t change the outcome, here’s some examples.
~~ Client Side ~~
CaptureClient

~~ Server Side ~~

CaptureServer

Yes 100% sure

I’m stumped. Does moving it to StarterGui do anything?

It does the exact same as StarterPlayerScripts, and StarterCharacterScripts. I just tested it.
I feel like I’m calling every player somehow is there a way to check this?

Ok, I think I may have a solution.
.Touched fires for everyone, because it is looking for any part that has been touched and all clients are able to detect all parts. Make your script check if the part is part of the LocalPlayer’s character, and only have the action occur then.

1 Like

Hey, thanks for the response! I am still getting the exact same problem. How would you go about this? This was the change I tried.

Saw I put it it in the function. Doesn’t change if the localplayer is defined outside of the function either. Just tested. I’m so confused

if part:IsADecentantOf(player.Character) then
 --set color here
end

I tried this multiple ways I just get an error that reads

IsADecentantOf is not a valid member of MeshPart "Workspace.breenud39.RightLowerLeg"

Did you make a typo and do .IsADecentantOf instead of :IsADecentantOf?

No I did not, I basically copied yours. And retyped it in my scripts, roblox even was giving the next syntax which normally means it’s in the right section I did use :IsADecentantOf

It’s not IsADescendantOf. It’s IsDescendantOf.

Found it in the documentation of Instance.

1 Like

Yes I used that, am I putting it in the wrong spot maybe? I made it right after the touch function.

1: Use remote to send part then change blick color
2: Maybe Roblox’s bug.

So I got it to work with the descendant function but same error…

That’s not what they’re asking for. They want it to change only on the client.

I was trying not to rewrite all my code in serverscript then remote function to client. As this function should be client side either way it’s under localscript. But for some reason it gets all character instead of just the one that is needed

if its local player should be:

local player = game:GetService("Players").LocalPlayer

(not sure if that may fix it but thats all i can think of