Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't my gampass script work?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago
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.

0
The script worked, but what I was hoping for was that they get it after respawning too. kelimeguy 60 — 8y
0
If you reset it won't give you it kelimeguy 60 — 8y
0
Edited, it will now do that. Evadable 65 — 8y
0
Now it won't give the hat to he character at all. kelimeguy 60 — 8y
0
nvm it worked! ty! kelimeguy 60 — 8y
Ad

Answer this question