So I have a tool (Pizza) and when I put it in ServerStorage it works but when I put it in ReplicatedStorage it does not work,
Here is the script that gives me tool:
local player = game.Players.LocalPlayer
local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,81487018)
if ownsGamepass then
local sword = game:GetService("ReplicatedStorage"):WaitForChild("Pizza"):Clone()
sword.Parent = player.Backpack
end
That’s when it is in RS
Here is when it is in SS:
local player = game.Players.LocalPlayer
local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,81487018) ------ Your Gamepass ID here
if ownsGamepass then
local sword = game:GetService("ServerStorage"):WaitForChild("Pizza"):Clone() -------- Change "ClassicSword" to your tool's name
sword.Parent = player.Backpack
end
But in RS it doesn’t work,
Anyone know what is the problem?
Thanks
You cant access ServerStorage on LocalScripts (Client)
Script [ ServerScriptService ]
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local Tool = ServerStorage.Pizza -- Tool location
local Gamepass = 81487018 -- Gamepass id
local function CheckIfUserHasGamePass(UserId : number, GamepassId : number) : boolean
local UserHasGamepass = false
local Works, HasGamepass = pcall(function()
return MarketPlaceService:UserOwnsGamePassAsync(UserId, GamepassId)
end)
if Works and HasGamepass == true then
UserHasGamepass = true
elseif not Works then
local Attempts = 0
repeat task.wait(1)
Works, HasGamepass = pcall(function()
return MarketPlaceService:UserOwnsGamePassAsync(UserId, GamepassId)
end)
Attempts += 1
until Works or Attempts >= 5
if Works and HasGamepass == true then
UserHasGamepass = true
end
end
return UserHasGamepass
end
Players.PlayerAdded:Connect(function(Player)
if CheckIfUserHasGamePass(Player.UserId, Gamepass) or game["Run Service"]:IsStudio() then
local ClonedTool = Tool:Clone()
local ClonedTool2 = Tool:Clone()
ClonedTool.Parent = Player.Backpack
ClonedTool2.Parent = Player.StarterGear
end
end)
That’s odd, it should be working the opposite way around since the client cannot see ServerStorage (like said above)
However, for gamepasses you should be making the script on the server:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId,81487018) then
ServerStorage:WaitForChild("Pizza"):Clone().Parent = player.Backpack
ServerStorage:WaitForChild("Pizza"):Clone().Parent = player.StarterGear -- Makes it so that the player receives the gear every time they respawn
end
end)