Changing texture from local script only changes on client side

Hello all. I have a flag system (utilising meshes in a tool) where you can change the texture via clicking a button. It works, but not how I intended. It only changes the texture client side not server side. I am utilising a local script (Shown below.) I have tried getting the flag tool using script.Parent but it had a meltdown toing that. This is my layout!

local player = game.Players.LocalPlayer.Name
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local flag = game.Workspace:FindFirstChild(player):WaitForChild("Flag")
local AnimatedFlag = flag:WaitForChild("Handle"):WaitForChild("Model"):WaitForChild("AnimatedFlag"):WaitForChild("Flag")
local AnimFlagParts = AnimatedFlag:GetDescendants()

local FlagTex = require(ReplicatedStorage.FlagTextures)

local GreenButton = container.Green.TextButton
local YellowButton = container.Yellow.TextButton
local RedButton = container.Red.TextButton
local BlueButton = container.Blue.TextButton
local WarningButton = container.Warning.TextButton
local BlackButton = container.Black.TextButton
local CheckeredButton = container.Finished.TextButton
local RYSButton = container.Track.TextButton
local WhiteButton = container.White.TextButton

local function find()
	if not script.Parent.Parent:FindFirstChild("Credits") then
		script.Parent.Parent.Parent:Destroy()
	end
end



GreenButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
	if descendants:IsA("MeshPart") then
		descendants.TextureID = FlagTex.Green
	end
end
end)

YellowButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
		if descendants:IsA("MeshPart") then
			descendants.TextureID = FlagTex.Yellow
		end
	end
end)

RedButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
		if descendants:IsA("MeshPart") then
			descendants.TextureID = FlagTex.Red
		end
	end
end)

BlueButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
		if descendants:IsA("MeshPart") then
			descendants.TextureID = FlagTex.Blue
		end
	end
end)

WarningButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
		if descendants:IsA("MeshPart") then
			descendants.TextureID = FlagTex.Warning
		end
	end
end)

BlackButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
		if descendants:IsA("MeshPart") then
			descendants.TextureID = FlagTex.Black
		end
	end
end)

CheckeredButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
		if descendants:IsA("MeshPart") then
			descendants.TextureID = FlagTex.Checkered
		end
	end
end)

RYSButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
		if descendants:IsA("MeshPart") then
			descendants.TextureID = FlagTex.SlipperyTrack
		end
	end
end)

WhiteButton.MouseButton1Click:Connect(function()
	for _, descendants in pairs(AnimFlagParts) do
		if descendants:IsA("MeshPart") then
			descendants.TextureID = FlagTex.White
		end
	end
end)```
1 Like

Use a RemoteEvent to change it on the server. Anything done on the client stays on the client (excluding things like network ownership).

1 Like

Yes, that is what a local script does. It only changes on the client side. You would need a remote event so that a server script can connect and perform a request on behalf of the local script to create the textures.

Another valid option is to have the server use :FireAllClients() to make every client create the texture but new joining players won’t see the texture unless you design your code somehow to work for this. The first option is probably better.

Also, be careful what you’re sending over the remote and making the server do. For example, don’t have the remote take a TextureId, or else an exploiter can spoof it and change the texture. This probably doesn’t matter if your game is single-player though.

1 Like

Will try this. How and what would have to be changed in the code to make this work. Im not much of a scripter sorry.

1 Like

There are some tutorials online for remote events. You’ll need a server script, a separate script from your code. And you’d have to change the local script.

1 Like

well yeah it makes sense, since local scripts are exucable and only render to the client that executed them so the changes will only occur to the client, in order to makes those changes take place on the server too you can do that via network communication (remote events)

here’s the documentation:

hope you find it helpful

1 Like

Will read through it thanks. Dont know why i thought a local script would work. Guess i werent thinkin straight!