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

Why doesn't my gampass script work?

My script is supposed to give your character a certain hat if you own a gamepass. There is a hat in serverstorage called cap that you get. I also have a character override script in use if that helps.

gpid = 339516128  
hats = {"Cap"}

GPS = game:GetService("GamePassService") 
function respawned(char) 
char = game.Players:FindFirstChild(char.Name) 
if char:FindFirstChild("Head") ~= nil then 
if game:GetService("MarketplaceService"):PlayerOwnsAsset(char,gpid) then
for i = 1,#hats do
game.ServerStorage:FindFirstChild(hats[i]):Clone().Parent = char
end 
else 
end 
end 
end 
game.Workspace.ChildAdded:connect(respawned) 

1 answer

✓ Accepted answer
gpid = 339516128  
hats = {"Cap"}

GPS = game:GetService("GamePassService") 
function respawned(char) 
local plr = game.Workspace:WaitForChild(char.Name)
local HatTag = Instance.new("IntValue")
HatTag.Name = "HatTag"
HatTag.Parent = char
if plr:FindFirstChild("Head") ~= nil then 
if game:GetService("MarketplaceService"):PlayerOwnsAsset(char,gpid) then
for i = 1,#hats do
game.ServerStorage:FindFirstChild(hats[i]):Clone().Parent = plr
end
char.Changed:connect(function(property) Respawn(property, char) end) --Checks to see if this player has died by using ".Changed"
else 
end 
end 
end 
game.Players.PlayerAdded:connect(respawned)

function Respawn(property, player)
	for i = 1,#hats do
game.ServerStorage:FindFirstChild(hats[i]):Clone().Parent = player.Character --Puts the hat back on the character.
	end
end

I would also recommend putting the 'Cap' in ReplicatedStorage, as it is the replacement for Lighting, Server Storage is used for other things.

5 comments

0

The script worked, but what I was hoping for was that they get it after respawning too.

0

If you reset it won't give you it

0

Edited, it will now do that.

0

Now it won't give the hat to he character at all.

0

nvm it worked! ty!

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