Help to make a system of skins for weapons

I want to create a skin system for swords. I created a button that should change the texture of the sword when pressed.
This certainly works, but the texture will change only if I have the nickname Pro_OLD31, what should I write instead of “Pro_OLD31” so that every player can change the skin.

script.Parent.MouseButton1Click:Connect(function()
	game.Players.Pro_OLD31.Backpack.Sword.Handle.Mesh.TextureId = "rbxassetid://129239835607605"
end)


image

I tried to search for an answer on the forum, but I did not find the right one.
thank you in advance

2 Likes

Do you want the skin to be visible by every player or just locally?

The skin should be visible to every player, I made a regular script and not a local one.

Create a LocalScript inside the button:

script.Parent.Activated:Connect(function()
game.ReplicatedStorage.ChangeSkin:FireServer("rbxassetid://129239835607605")
end)

Create a server script inside ServerScriptService:


game.ReplicatedStorage.ChangeSkin.OnServerEvent:Connect(function(player, skinID)
local sword = player.Backpack:FindFirstChild("Sword") or player.Character:FindFirstChild("Sword")
	sword.Handle.Mesh.TextureId = skinID
end)

And then create a RemoteEvent inside ReplicatedStorage and then name it “ChangeSkin”

Keep in mind that this code will allow players to use any skin they want

1 Like

Thanks, but how do I make the skin persist after a reset or exit?

Just store the sword inside StarterGear when the skin gets changed. Once the player resets, it will put the sword from StarterGear into Backpack with the skin applied.

1 Like

Could you describe in more detail how to add a sword to Starter Gear?

sword:Clone().Parent = player.StarterGear

This works, but then a second sword appears on reset, one with a skin and the other without.
image

You’ll have to remove that sword without the skin since you have a sword without a skin in StarterPack which replicates to the player’s Backpack.

Having it persist after a server shutdown or game exit requires using datastores.Those are pretty advanced, definitely not beginner friendly.