We want to change Client to Server this script

--localScript
local imageButton = script.Parent

local function changeAvatar()

	-- Get the local player's character
	local player = game.Players.LocalPlayer.Character

	-- Change the texture of the character's parts
	for _, part in ipairs(player:GetDescendants()) do
		if part:IsA("MeshPart") then
			part.TextureID = imageButton.Image
		end
	end
end

imageButton.MouseButton1Click:Connect(changeAvatar)

Imagen de WhatsApp 2024-01-05 a las 08.02.13_f2916abd

As we did on the button sending the information is apart of the principal script , is better if we put the order on the script on server? the event?

2 Likes
local players = game:GetService("Players")

local changeSkinRemote = game.ReplicatedStorage.SkinsEvent 

changeSkinRemote.OnServerEvent:Connect(function()
	-- Your skin changing logic goes here.
	local imageButton = game.StarterGui.SkynsShop.ShopSkyns.ScrollingFrame.ImageButton

	local function changeAvatar(UserId)
		
		-- Get the local player's character
		local Player = game:GetService(UserId)--change to server player

		-- Change the texture of the character's parts
		for _, part in ipairs(Player:GetDescendants()) do
			if part:IsA("MeshPart") then
				part.TextureID = imageButton.Image
			end
		end
	end

	imageButton.MouseButton1Click:Connect(changeAvatar)


end)


we adapt the script to ther server on serverscript service to general function, but it´s not working the changing and show

1 Like
--localScript
local imageButton = script.Parent
local changeSkinEvent = game.ReplicatedStorage.ChangeSkin
-- Path to the remote

local player = game.Players.LocalPlayer

local function changeAvatar()
changeSkinEvent:FireServer(imageButton)
end

imageButton.MouseButton1Click:Connect(changeAvatar)

-- ServerScript
local changeSkinEvent = game.ReplicatedStorage.ChangeSkin

changeSkinEvent.OnServerEvent:Connect(function(player, imageButton))

	-- Change the texture of the character's parts
	for _, part in ipairs(player:GetDescendants()) do
		if part:IsA("MeshPart") then
			part.TextureID = imageButton.Image
		end
	end
end)
1 Like

Good morning, in the end we have found the solution after trying and with the super help offered, we finally managed to connect the scripts:
FIRST SCRIPT, the marketplace with the GUI opening button, Skins (with the script provided.

--LOCAL SCRIPT FOR BUTTON OPEN GUI IF YOU HAVE THE GAME PASSID

local MarketplaceService = game:GetService("MarketplaceService")
local GamepassID = 12345 -- Change to your Gamepass ID
local button = script.Parent.Parent.ShopSkyns.CloseSkyns
local player = game.Players.LocalPlayer
local frame = script.Parent.Parent.ShopSkyns

script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) --THIS FUCTION CLICK TO BUTTON 

if hasPass then  -- IF YOU HAVE THE PASS SHOW THE GUI

	frame.Visible = true
		button.Rotation = 180
	for i = 1, 10 do
		frame.Position = UDim2.new(0.3, 0, -i/120 + 0.4 , 0)
		wait(0.01)
	end

else
	local purchasePrompt = MarketplaceService:PromptGamePassPurchase(player, GamepassID)
	purchasePrompt.Completed:Connect(function(purchaseSuccess)
		if purchaseSuccess then
			frame.Visible = true

			for i = 1, 10 do
				frame.Position = UDim2.new(0.02, 0, -i/120 + 0.5 , 0)
				wait(0.01)
			end
		else
			frame.Visible = false
				button.Rotation = 180
--end
		end
	end)
end
end)

SECOND SCRIPT
the server script that receives the event for the GUI buttons, and their textures.

--SERVER CRIPT ON SERVERCRIPTSERVICE

local changeSkinEvent = game.ReplicatedStorage.ChangeSkinEvent


changeSkinEvent.OnServerEvent:Connect(function(player, imageButton)
	-- Change the texture of the character's parts on workspace.Player.character
	for _, part in ipairs(player.Character:GetDescendants()) do
		if part:IsA("MeshPart") then
			part.TextureID = imageButton.Image
		end
	end
end)

THIRD SCRIPT
The button script that sends the event order to change the skin, and can be seen by all users, regardless of the user (custom)

--localScript ON IMAGE BUTTON
local imageButton = script.Parent
local changeSkinEvent = game.ReplicatedStorage.ChangeSkinEvent --PICK UP THE EVENT 

local player = game.Players.LocalPlayer

local function changeAvatar() --CONECT EVENT ON CLICK BUTTON  AND SEND THE SKIN IN TO THE SERVER
	changeSkinEvent:FireServer(imageButton)
end

imageButton.MouseButton1Click:Connect(changeAvatar)

Thank you very much for your help :smiling_face:, it has been great, and it has helped us better understand the change from local to server, thank you very much

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.