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

Accessory Giver GUI if player HasPass, how to?

I've done some research upon making a accessory giver gui if a player has the gamepass. The 'PlayerHasPass' Would function as a button, so if the player has the gamepass, they're able to click the button which opens the gui.

That being said, that gui would have accessory decals which if clicked, that accessory would be added to your character, and other accessories you have would be removed. I've yet to find a proper way to do this script, and tried to do so without having to use a gui, just with ServerScripts, but those didn't seem to work, so I've turned to this once again. Any and all help is appreciated! Variables; The ScreenGui would be named 'HatGui' id; 5949403

Everything else I don't know. Thank you all for your help!

1 answer

✓ Accepted answer

Local Script

local Market = game:GetService("MarketplaceService")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("AttachHat")
local Player = game.Players.LocalPlayer

local ButtonGui = script.Parent
local Gui = ButtonGui.Parent:WaitForChild("HatGui")

ButtonGui.TextButton.Activated:Connect(function()
	if Market:UserOwnsGamePassAsync(Player.UserId, 5949403) then
		Gui.Enabled = true
		ButtonGui.Enabled = false
	else
		Gui.Enabled = false
		ButtonGui.Enabled = true
	end
end)

for i, v in pairs(Gui:GetDescendants()) do
	if v:IsA("ImageButton") then
		v.Activated:Connect(function()
			Remote:FireServer(v.Name)
		end)
	end
end

Server Script

local Remote = Instance.new("RemoteEvent")
Remote.Name = "AttachHat"
Remote.Parent = game:GetService("ReplicatedStorage")

Remote.OnServerEvent:Connect(function(Player, Button)
	for i, v in pairs(Player.Characer:GetDescendants()) do
		if v:IsA("Accessory") then
			v:Destroy()
		end
	end
	
	local newaccessory = Instance.new("Accessory")
	newaccessory.Parent = Player.Character
	
	local newhandle = Instance.new("Part")
	newhandle.Parent = newaccessory
	newhandle.Size = Vector3.new(1, 1, 1)
	newhandle.CanCollide = false
	newhandle.Anchored = false
	
	local newmesh = Instance.new("SpecialMesh")
	newmesh.Parent = newhandle
	newmesh.Scale = Vector3.new(1, 1, 1)
	
	local newweld = Instance.new("Weld")
	newweld.Part1 = Player.Character:WaitForChild("Head")
	newweld.Part0 = newhandle
	
	if Button == "Button1" then
		newweld.C0 = CFrame.new(0, 0, 0)
		newmesh.MeshId = "http://www.roblox.com/asset/?id=0"
		newmesh.TextureId = "http://www.roblox.com/asset/?id=0"
	end
end)

UserOwnsGamePassAsync is used to get the GamepassId, UserHassPass is deprecated

You need to use Remote Events (one is created in the Server Script for you) in order to communicate between the Server and the Client

In this example, there are two ScreenGuis (one for the button to open the hat gui) Place your TextButton / LocalScript into the "ButtonGui" and the ImageButtons into the "HatGui"

If you add Frames, make sure to account for these in the definitions of Gui and ButtonGui

The thing to edit for each button is to make sure that the name of the button matches a string as shown by if (Button = "Button1" then) then alter the offset (c0) and mesh / texture accordingly.

Make sure the Hat Gui "Enabled" property is disabled first

7 comments

0

Would newweld.C0 = CFrame.new(0, 0, 0) Stay the same as 0's or would they be 1's if a new hat is added?

0

you are manually setting it so it would stay at (0,0,0), but you'd need to make sure the offset is correct in a test server

0

that's why the if-then since the mesh / texture / cframe will be different for each accessory

0

Ah alright.

0

So the 'locsl script' Is put into the TextButton that opens the gui, or the imagebutton that puts the hat on the players head?

0

the local script that opens the textbutton, according to this script, is placed directly into the gui that the textbutton is parented under. You should have two screen guis

0

Alrighty.

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