Help on creating a player cosmetic that affects a server instance

I have a game where players have to click on three buttons, a red, yellow, and green button. During each round, they would be spawned in on the server from a folder in the ReplicatedStorage. I thought it would be a cool idea if the player could customize these buttons to their liking though an in-game shop.

So, I created a local script that I thought would change the buttons appearance, by either replacing its instance in the ReplicatedStorage, or changing its color properties. However, I forgot one main thing about ReplicatedStorage, and that anything in it was only a copy of what the server had, and not the actual object of the buttons being spawned.

I tried looking for any solutions in the DevForum, and it looks like I would have to do some hacky stuff to try to replicate what the player wants the button to look like. I was thinking of changing each button’s properties when its cloned to the workspace, but it doesn’t sound that efficient.

Is there a way I could achieve this in a way that won’t feel that I done something really wrong? I feel that I should just abandon this for the time being. Any help or feedback would be appreciated!

Code, warning: it's not so great
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local localPlayer = Players.LocalPlayer

local playerinventory = localPlayer:WaitForChild("playerinventory")
wait(1)
local buttonColor = playerinventory:WaitForChild("BUTTON_COLOR")
local buttonType = playerinventory:WaitForChild("BUTTON_TYPE")

local buttons = ReplicatedStorage:WaitForChild("Buttons")
local redButton = buttons:WaitForChild("RedButton"):WaitForChild("Button")
local yellowButton = buttons:WaitForChild("YellowButton"):WaitForChild("Button")
local greenButton = buttons:WaitForChild("GreenButton"):WaitForChild("Button")

local buttonColors = ReplicatedStorage:WaitForChild("ButtonColors")
local buttonTypes = ReplicatedStorage:WaitForChild("ButtonTypes")
local normalButtons = buttonTypes:WaitForChild("Normal")

local IM = require(ReplicatedStorage.ItemManager)

local function resetButtonColors()
	redButton.Color = Color3.fromRGB(255, 0, 0)
	yellowButton.Color = Color3.fromRGB(255, 255, 0)
	greenButton.Color = Color3.fromRGB(0, 255, 0)
end

local function updateButtonColor(id,buttonTypeId)	
	if id ~= 0 then
		local buttonColor = IM:getItemFromId(IM.BUTTON_COLORS,id)["Object"]
		local redButtonColor = buttonColor:WaitForChild("RedButton"):WaitForChild("Button").Color
		local yellowButtonColor = buttonColor:WaitForChild("YellowButton"):WaitForChild("Button").Color
		local greenButtonColor = buttonColor:WaitForChild("GreenButton"):WaitForChild("Button").Color
		local overrideButtonColors
		if buttonTypeId ~= 0 then
			overrideButtonColors = IM:getItemFromId(IM.BUTTON_TYPES,buttonTypeId)["OverrideButtonColors"]
		end
		if buttonTypeId ~= 0 and not overrideButtonColors then
			redButton.Color = redButtonColor
			yellowButton.Color = yellowButtonColor
			greenButton.Color = greenButtonColor
		end
	else
		resetButtonColors()
	end
end

local function resetButtonType(overrideButtonColors)
	local normalButtonsClone = normalButtons:Clone()
	normalButtonsClone.Name = "Buttons"
	
	buttons:Destroy()
	
	normalButtonsClone.Parent = ReplicatedStorage
	buttons = normalButtonsClone
	
	if overrideButtonColors then
		updateButtonColor(buttonColor.Value,buttonType.Value)
	end
end

local function updateButtonType(id,buttonColorId)
	local buttonType
	local overrideButtonColors
	if id ~= 0 then
		buttonType = IM:getItemFromId(IM.BUTTON_TYPES,id)["Object"]:Clone():GetChildren()
		overrideButtonColors = IM:getItemFromId(IM.BUTTON_TYPES,id)["OverrideButtonColors"]
		
		local buttonColor
		local redButtonColor
		local yellowButtonColor
		local greenButtonColor
		if buttonColorId ~= 0 then
			buttonColor = IM:getItemFromId(IM.BUTTON_COLORS,buttonColorId)["Object"]
			redButtonColor = buttonColor:WaitForChild("RedButton"):WaitForChild("Button").Color
			yellowButtonColor = buttonColor:WaitForChild("YellowButton"):WaitForChild("Button").Color
			greenButtonColor = buttonColor:WaitForChild("GreenButton"):WaitForChild("Button").Color 
		end
		
		buttons:ClearAllChildren()
		for _,button in ipairs(buttonType) do
			button.Parent = buttons 
		end
		--buttonType:Destroy()
		
		redButton = buttons:WaitForChild("RedButton"):WaitForChild("Button")
		yellowButton = buttons:WaitForChild("YellowButton"):WaitForChild("Button")
		greenButton = buttons:WaitForChild("GreenButton"):WaitForChild("Button")
		
		if buttonColorId ~= 0 and not overrideButtonColors then
			redButton.Color = redButtonColor
			yellowButton.Color = yellowButtonColor
			greenButton.Color = greenButtonColor
		end
	else
		resetButtonType(overrideButtonColors)
	end
end

updateButtonColor(buttonColor.Value,buttonType.Value)
updateButtonType(buttonType.Value,buttonColor.Value)

buttonColor.Changed:Connect(function(id)
	updateButtonColor(id,buttonType.Value)
end)

buttonType.Changed:Connect(function(id)
	updateButtonType(id,buttonColor.Value)
end)

Not entirely sure what you’re trying to do. But from what I read, you can just clone the button from ReplicatedStorage, parent it to GUI in PlayerGui, and then you can just use a local script to modify its properties like color.

Maybe this video will help you? Excuse the very poor roblox recorder quality.

The only way to do this would be to clone the buttons through the server so all players can see and wait for the buttons to spawn on the client and change to custom colors.

1 Like

I see, but would that affect performance to where it’ll lag? I’m also planning to change other properties such as transparency and reflectance (and even shape).

I dont think performance would matter in this scenerio.

1 Like

Wow, I definitely overthought how big the problem was. I just finished rewriting the script, and it was actually less problematic than what I had before! (I love CollectionService)

Thank you for helping me out!

Glad you found a solution. Its good that you thought about the implementation of the idea before doing it. Hope your game becomes successful.

1 Like