I have no clue why, but sometimes this script works and sometimes it doesn’t.
local RS = game:GetService("ReplicatedStorage")
local sword = RS.Tools:WaitForChild("ClassicSword")
local players = game:GetService("Players")
local MS = game:GetService("MarketplaceService")
local productIDs =
{
swordPass = "18246407"
}
players.PlayerAdded:Connect(function(player)
if MS:UserOwnsGamePassAsync(player.UserId, productIDs["swordPass"]) == true then
wait(.1)
local cloneSword = sword:Clone()
cloneSword.Parent = player:WaitForChild("Backpack")
end
end)
Sorry if this is a super basic question, still very new to scripting
Yep, and again, it sometimes works and sometimes doesn’t but the thing is it never errors, so I’m not led to believe it’s an issue with something not loading, plus I’m also not given any infinite yields.
It should be a number and you should add it into their character once it spawns.
local RS = game:GetService("ReplicatedStorage")
local sword = RS.Tools:WaitForChild("ClassicSword")
local players = game:GetService("Players")
local MS = game:GetService("MarketplaceService")
local productIDs =
{
["swordPass"] = 18246407
}
players.PlayerAdded:Connect(function(player)
if MS:UserOwnsGamePassAsync(player.UserId, productIDs["swordPass"]) == true then
repeat
wait()
until player.Character
local cloneSword = sword:Clone()
cloneSword.Parent = player:WaitForChild("Backpack")
end
end)
Busy waiting here is unnecessary when there are events to detect when character adds .
Just do
local RS = game:GetService("ReplicatedStorage")
local sword = RS.Tools:WaitForChild("ClassicSword")
local players = game:GetService("Players")
local MS = game:GetService("MarketplaceService")
local productIDs =
{
swordPass= 18246407
}
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Char)
if MS:UserOwnsGamePassAsync(player.UserId, productIDs.swordPass) then
local cloneSword = sword:Clone()
cloneSword.Parent = player.Backpack
end
end)
end)
This worked, thank you, also just wondering would this work the same?
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
if MS:UserOwnsGamePassAsync(player.UserId, productIDs.swordPass) then
local cloneSword = sword:Clone()
cloneSword.Parent = player.Backpack
end
end)