Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make it so that when a player clicks on a button it changes the mesh of their character?

I am having trouble with my scripts. Here they are:

This is the script that is placed in the Button the player clicks:

local player = game.Players.LocalPlayer
wait()
local leaderboard = player.leaderstats
local button = script.Parent
local price = button:WaitForChild("Price")
local mesh = button:WaitForChild("MeshName")

button.MouseButton1Click:Connect(function()
    if leaderboard.Level.Value >= price.Value then
        game.ReplicatedStorage.MeshEvents.ChangeMeshSquare:FireServer(player.Name, mesh) 
    end
end)

This is the script that is placed in ServerScriptService:

game.ReplicatedStorage.MeshEvents.ChangeMeshSquare.OnServerEvent:Connect(function(player, mesh)
    if workspace:FindFirstChild(player.Name) then
		print("found")
        if workspace[player.Name]:FindFirstChild("Torso") then
            workspace[player.Name].Torso.Mesh.MeshId = MeshId.new("1171241994")
				workspace[player.Name].Torso.Mesh.Scale = Scale.new("0.02, 0.02, 0.02")
        end
    end
end)

And The Remote Event is named "ChangeMeshSquare" in ReplicatedStorage. Idk where I went wrong I think it is the way I accessed the Mesh inside the player torso.

(The player is custom so StarterCharacter in StarterPlayer

1 answer

Likely, the problem is your arguments in your :FireServer(). This method does not require any arguments, but you can send any information you like with it. On the other side of the remote - the OnServerEvent in your case - the first parameter passed is always the client that fired the event. Therefore, even if you send nothing in the :FireServer(), that parameter will still exist. Based on this, you can clearly see your problem.

Remove the player argument in the :FireServer(): game.ReplicatedStorage.MeshEvents.ChangeMeshSquare:FireServer(mesh)

Now your parameters in the server-sided are player and mesh, respectively.

This discussion is preserved as it was. New answers, comments, and votes are closed.