local gamePassID = 0000000
game.Players.PlayerAdded:Connect(function(player)
local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,gamePassID)
if ownsGamepass then
local sword = game:GetService("ReplicatedStorage"):WaitForChild("Giant"):Clone()
sword.Parent = player.Backpack
plr.Humanoid:EquipTool(sword)
end
end)
This Code Works İn The Studio, But İt Does Not Work İn The Normal Game, There İs a Problem With The Script
I think the error could be that you are using plr rather than player on this line.
This is because you have a player variable which is called player but you are using plr instead. Maybe try changing plr to player on that line.
Edit: You might also need to wait for the player’s character as the script might be executing before the character has loaded in. I think you can do this with player.CharacterAdded:wait()
There’s a few things I can see that could make the script error, here’s an edited version with some comments explaining what was wrong.
local MarketplaceService = game:GetService("MarketplaceService") -- this isn't required, but makes your script look much cleaner
game.Players.PlayerAdded:Connect(function(player)
local ownsGamepass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) -- separate function arguments with spaces please (again, makes code cleaner)
if ownsGamepass then
local sword = game:GetService("ReplicatedStorage"):WaitForChild("Giant"):Clone() -- If the client doesn't need to see this, you should put this in ServerStorage instead
sword.Parent = player.Backpack
local character = player.Character or player.CharacterAdded:Wait() -- get the player's character, and if it hasn't loaded in yet we wait until it does
local humanoid = character :WaitForChild("Humanoid") -- wait for the humanoid
humanoid:EquipTool(sword)
end
end)