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

if player has gamepass then on click equip hat?

hello so i am not that good at scripting but i tried to make that you can equip the hat here is the script local gamePassID = 9843545

script.Parent.ClickDetector.MouseClick:connect(function(player) if playerhasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId) game.ServerStorage["Hat"]:Clone().Parent = player.Accessory if player has Accessory {""hat"} then unequip then wait (10)

    end
end)

1 answer

✓ Accepted answer

Usually, scripts for GUIs are LocalScripts. That's because GUIs are client-sided. So I'm assuming you're using a LocalScript; however, you're trying to access an object in ServerStorage which cannot be done because ServerStorage can only be accessed by the server. I would recommend that you use a RemoteEvent because if you clone something on the client, other players cannot see the item and it's just local to the player. Below is your script which I fixed up for you and left some comments for you to read.

local gamePassID = 9843545

script.Parent.ClickDetector.MouseClick:Connect(function(player) -- Capitalize the C in Connect, as "connect" is deprecated
	if MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID) then -- your second parameter needs to be the gamepass ID. This is checking if player does have game pass
		game.ServerStorage["Hat"]:Clone().Parent = player.Accessory -- learn about RemoteEvents and fire one to make the server clone this
		if player:FindFirstChild("Hat") then -- you cannot search for an item by doing "if player has hat then"
			unequip then -- learn your syntax please. You can't unequip something by saying "unequip". You also have to be specific
			wait (10) 
		end
	end
end)

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