How work localscript for brickcolor

I making a building that can be changed and can be seen that changed by only owner.
SO m using local script for here

But…

Brickcolor order does not work in localscript, but do work in normal script.

whoever help… Does it originally not work in localscript? If it does, How can I make them?

Here are two sources to help you out:
Documentation:

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service

Therefore put it in player starter scripts to make it run once then do workspace:WaitForChild(“TouchPart”) or use game.IsLoaded to get the part (wait for the stuff in workspace to load first, then do the touched event).

You will also need to make sure the person who triggered Touched event is the local player as well because physics replicate and avoid this issue:

1 Like

local scripts do not work in workspace.

Hey there. It’s possible to change the brickcolor through LocalScript. You can make RemoteEvent and FireServer on touch to change the brickColor. (Note: LocalScript doesn’t work in workspace)

ServerScript:

local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(Player, Part)

Part.BrickColor = BrickColor.new("Really black")

end)

StarterPlayerScript:

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

local part = workspace.Part

part.Touched:Connect(function(hit)

if hit.Parent.Name == Player.Name then

RemoteEvent:FireServer(part)

end

end)

If you want to run locally only try this:

local Player = game:GetService("Players").LocalPlayer
local part = workspace.Part

part.Touched:Connect(function(hit)
	if hit.Parent.Name == Player.Name then
		part.BrickColor = BrickColor.new("Really black")
	end
end)
1 Like

You meant it works in Gui easily?

OHhhh
My Real plan is the button in PlayerGui, not the touchpart(It was just test for localscript)!
If player press button at Gui, It changes the building ya

I didnt know it 'soo different to manage localscript part and localscript Gui.