Texture not changing

Right so,

I’ve been working on a custom material feature for my build mode system. Basically, it changes all the textures found in an object, by clicking a button. You need to input the texture ID, and then you can change the texture of any object.

My problem is, the textures doesn’t change, even tho everything in the client side works perfect. But on the actual server, nothing happens…

Here’s my code:

TextBox:

script.Parent.FocusLost:Connect(function(enter)
	if enter then
		if script.Parent.Text then
			script.Parent.Parent.MaterialPreview.Image = "rbxassetid://" .. script.Parent.Text
			
			local asset = game:GetService("MarketplaceService"):GetProductInfo(tonumber(script.Parent.Text), Enum.InfoType.Asset)
			
			script.Parent.Parent.MaterialPreview.AssetName.Text = asset.Name
			
			script.Parent.Parent.Material.Value = "rbxassetid://" .. script.Parent.Text
		end
	end
end)

This part changes the StringValue to the given ID. Which it will be used to be defined as the material

Important lines in the button script:

local newMaterial = script.Parent.Parent.Material.Value -- The string value

RE:FireServer(target, newMaterial) -- Fires a remote event, its arguments are the Mouse target and the material which is the value of that string value

Server script:

game.ReplicatedStorage.Events.materialObjCustom.OnServerEvent:Connect(function(Player, Object, Material)
	for i, mat in Object:GetDescendants() do
		if mat:IsA("Texture") then
			mat.Texture = Material
		end
	end
end)

This is a very simple feature, but everything is messed up now…

Please help, thanks.

Do you have this in 2 scripts? I would try combining it all in 1 script. Also, to save resources, I also make a variable inside the script rather than using a separate StringValue.

local Texture
local Target = Object.Value -- Guessing this is an ObjectValue. 

script.Parent.FocusLost:Connect(function(enter)
	if enter then
		if script.Parent.Text then
			Texture = "rbxassetid://" .. script.Parent.Text
			script.Parent.Parent.MaterialPreview.Image = Texture
			
			local asset = game:GetService("MarketplaceService"):GetProductInfo(tonumber(script.Parent.Text), Enum.InfoType.Asset)
			
			script.Parent.Parent.MaterialPreview.AssetName.Text = asset.Name
			
			
			Button.MouseButton1Click:Connect(function()
				RE:FireServer(Target, Texture) -- Fires a remote event, its arguments are the Mouse target and the material which is the value of that string value
			end)
		end
	end
end)

I’ll try to do that.

Any ideas on some changes in the server script?

No, the ServerScript look good.

1 Like