How would I change a parts mesh on click?

Hi, I was wondering if there was a way to change a parts special mesh if they click a button and if they have > 100 coins (Client-Sided)

local WS = game:GetService("Workspace")
local TPS = WS:WaitForChild("TPS"):WaitForChild("Design")
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local stat = plr:WaitForChild("Leaderstatss").Coins.Value

local meshID = 4582910212
local textureID = 4761214875

script.Parent.MouseButton1Click:Connect(function()
	if stat == 0 then
		stat -= 0
		TPS.MeshId = meshID
		TPS.TextureId = textureID
		warn("Bought")
	else
	
	end
end)
1 Like

Do you want everyone to see that change? You can do this with RemoteEvent by verifying on the server that you have the indicated coins

1 Like

I only want one person to see the mesh.

You could just store a cloned mesh in ReplicatedStorage but with it’s mesh edited [Only edit mesh Id through properties]
Then If that person clicks on it, you clone the cloned mesh in workspace.

If your looking for Mesh Part, this is it.

Like this?

local WS = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local ball = WS:WaitForChild("TPS")
local TPS = WS:WaitForChild("TPS"):WaitForChild("Design")
local Mesh = ReplicatedStorage:WaitForChild("Design")


local plr = Players.LocalPlayer
local stat = plr:WaitForChild("Leaderstatss").Coins.Value

local meshID = 4582910212
local textureID = 4761214875

script.Parent.MouseButton1Click:Connect(function()
	if stat == 0 then
		stat -= 0
		TPS:Destroy()
		Mesh.MeshId = meshID
		Mesh.TextureId = textureID
		Mesh:Clone().Parent = ball
		warn("Bought")
	else
	warn("You dont have enough coins!")
	end
end)

You can use a RemoteFunction to do a sanity check, because an exploiter can edit Coins’ value on the client and give a false change.

local RS = game:GetService("ReplicatedStorage")

RS.RemoteFunction.OnServerInvoke = function(client)
	if client.leaderstats.Coins.Value > 100 then
		return true
	else
		return false
	end
end
local RS = game:GetService("ReplicatedStorage")

local Result = RS.RemoteFunction:InvokeServer()

if Result then
	-- Change MeshID locally.
end

Update, it doesn’t output anything when the button is click

Like I said, do not edit it through script, Make a MeshPart in studio then set the Mesh Id and Texture Id through properties then place it in ReplicatedStorage.
If the player clicks on it, you clone the mesh part then parent it to workspace.

You need to put rbxassetid:// in front of the numbers.

I will change that and see if it works later, thanks.

1 Like

sorry for bumping this up 1 month later, but it works, thanks!

1 Like