We want to change Client to Server this script

We did try a script for skins changing as a local, and all is working Good, but we need to put on server script, for every one see it.

Any one can help? Thankss

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)

if hasPass then

	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)
4 Likes

So you are saying that when you turn your script into a Server Script it doesn’t work anymore?

Can you also give a sample of your code?

1 Like

Sorry, we were editing the text :laughing:

2 Likes

The server can’t access game.Players.LocalPlayer

1 Like

we know, but as market place on the script we don´t know how to fix it, so we put the original script on local working

1 Like

You are trying to get the local player on the server, which returns nil

But the MouseButton1Click event does return the player

Try this:

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

script.Parent.MouseButton1Click:Connect(function(player)
local hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID)

if hasPass then

	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)

thank youuu!! :smiling_face:, that i think it is, let´s try if it Works

No work :pensive:

Players.Isaak_ll.PlayerGui.SkynsShop.SkynShopbutton.Script:7: attempt to index nil with ‘UserId’

there still something on the conection user id

The button you click on is a GuiButton, right?

Because if it’s a ClickDetector then change MouseButton1Click to MouseClick

1 Like

Maybe make a local script, make it so that when you click the button it fires a remote and make the check on a server script?

1 Like

that’s right, Yes It is a GuiButton

Then this would surely work

aa

You should handle this with 2 different scripts, 1 for server-side marketplace, and the other for receiving the user’s input, this would look something like this:

--LocalScript
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketPlaceService")
local Player = Players.LocalPlayer

local Button = script.Parent
Button.MouseButton1Click:Connect(function()
  if MarketPlaceService:UserOwnsGamepassAsync(Player.UserId, <GAMEPASS ID HERE>) then 
    -- The player owns the gamepass
  else
    -- The player does not own the gamepass
    <some remote event>:FireServer()
  end
end)
--Server Script
local MarketPlaceService = game:GetService("MarketPlaceService")
local Event = <some event>

Event.OnServerEvent:Connect(function(Player)
  MarketPlaceService:PromptGamepassPurchase(Player, <gamepass id>)
  MarketPlaceService.ProcessReceipt = function()
   -- Handle gamepass purchase
  end
end)
2 Likes

that makes sense, thanksss let’s try it :grinning:

Hello, I have tried to adapt the script as best we could, it gives me an error in:
‘MarketPlaceService’ is not a valid Service name
I understand how sending the event (ReplicatedStorage SkinsEvent) sends the information from the event to collect the SSService script.

but with our humble wisdom, since it is less difficult for us to see it, we keep trying!!

--Local Script
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketPlaceService")
local Player = Players.LocalPlayer
local Button = script.Parent.Parent.ShopSkyns.CloseSkyns

local Frame = script.Parent.Parent.ShopSkyns


Button.MouseButton1Click:Connect(function()
	if MarketPlaceService:UserOwnsGamepassAsync(Player.UserId, 651733501) then 
		Frame.Visible = true
		
		for i = 1, 10 do
			Frame.Position = UDim2.new(0.3, 0, -i/120 + 0.4 , 0)
			wait(0.01)
		end	
	else
		script.Parent.MouseButton1Click:Connect(function()
			
			game.ReplicatedStorage.SkinsEvent:FireServer()


		end)
		
	end
	
end)
--server script en ServerScriptService

local MarketPlaceService = game:GetService("MarketPlaceService")
local Event =game.ReplicatedStorage.SkinsEvent
local Button = script.Parent.Parent.StarterGui.SkynsShop.SkynShopbutton
local Frame = script.Parent.Parent.StarterGui.SkynsShop.ShopSkyns

Event.OnServerEvent:Connect(function(Player)
	MarketPlaceService:PromptGamepassPurchase(Player, 651733501)
	MarketPlaceService.ProcessReceipt = function()
		game.purchasePrompt.Completed:Connect(function(purchaseSuccess) -- purchaseSuccess is a boolean
			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
				
			end
		end)
		
	end
	
end)

Fire a RemoteEvent to the server and change it there too.

Example Code:

Client Side:

local changeSkinRemote = game.ReplicatedStorage.ChangeSkin -- Your path to the remote goes here.

-- Fire the remote when the desired action happens,
-- I don't fully know what you're trying to achieve with rotating a button and other stuff but when it happens, here it is, it fires.

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)

if hasPass then
-- Here, insert what you're trying to fire the server with.
changeSkinRemote:FireServer()
	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
-- Here, insert what you're trying to fire the server with.
changeSkinRemote:FireServer()

			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)

Server Side:

local changeSkinRemote = game.ReplicatedStorage.ChangeSkin -- Your path to the remote goes here.

changeSkinRemote.OnServerEvent:Connect(function()
-- Your skin changing logic goes here.
end)

Hope this works the best for you!

2 Likes

Thank You :smiling_face:!!! we are going to try

This is what we are doing

2 Likes

Did it work? Hope it does!

mAxImUmChArAcTeRLimIt

2 Likes

Thank you it works !!! It’s perfect!! Script… but still we don’t see each other’s skins. … How we do that?

--local script
local changeSkinRemote = game.ReplicatedStorage.SkinsEvent -- Your path to the remote goes here.

local MarketplaceService = game:GetService("MarketplaceService")
local GamepassID = 123456-- Change to your Gamepass ID

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)

	if hasPass then
		-- Here, insert what you're trying to fire the server with.
		changeSkinRemote:FireServer()
		frame.Visible = true
		
		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
				-- Here, insert what you're trying to fire the server with.
				changeSkinRemote:FireServer()

				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
				
				--end
			end
		end)
	end
end)

We should if we understood nice… The script with button conecction on this one?

-- ServerScriptService
local changeSkinRemote = game.ReplicatedStorage.SkinsEvent -- Your path to the remote goes here.

changeSkinRemote.OnServerEvent:Connect(function()
	-- Your skin changing logic goes here.
end)
2 Likes