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

The GamePass Item Works For Everyone If 1 Player Is On The Game?

Asked by 5 years ago

If Someone has Gamepass, And He Is Currently Playing The Game, Everyone Has The Trail (Item). Can Someone Help So The Gamepass Trail Only Works For Gamepass Users, Thanks!

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 5647766 -- Change this to your game pass ID 

function onPlayerSpawned(player) 

    local hasPass = false

    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
  print("Has Game Pass for Gun")
    end)

    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end

    if hasPass == true then


script.Parent.Touched:Connect(function(parttouched)
        local humanoid = parttouched.Parent:FindFirstChild("Humanoid")
        -- The above is how we check that this a human it's either the Humanoid or nil.
    if humanoid ~= nil then
        local char = humanoid.Parent
        local trail = game.ServerStorage.Yellow:Clone()
            trail.Parent  = char.Head
            local attachment0 = Instance.new("Attachment", char.Head)
            attachment0.Name = "TrailAttachment0"
        local attachment1 = Instance.new("Attachment", char.HumanoidRootPart)
            attachment1.Name = "TrailAttachment0"
        trail.Attachment0 = attachment0
        trail.Attachment1 = attachment1
    end
end)

else
    print("you got no pass")

 end
end 

game.Players.PlayerAdded:connect(function(player)
  player.CharacterAdded:connect(function()
    onPlayerSpawned(player)
  end)
end)

-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerSpawned:Connect(onPlayerSpawned)
0
this is super convoluted DinozCreates 1070 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

I'm not sure what you're doing. If anyone with the gamepass joins, anyone who then touches the brick will get the Trail.

Try this instead:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 5647766 -- Change this to your game pass ID 

script.Parent.Touched:Connect(function(Touched)
    local Player = Players:GetPlayerFromCharacter(Touched.Parent)
    if Player then -- Check if is Player
        if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamePassID) then
            local char = Touched.Parent

            local trail = game.ServerStorage.Yellow:Clone()
            trail.Parent  = char.Head

            local attachment0 = Instance.new("Attachment", char.Head)
            attachment0.Name = "TrailAttachment0"

            local attachment1 = Instance.new("Attachment", char.HumanoidRootPart)
            attachment1.Name = "TrailAttachment0"

            trail.Attachment0 = attachment0
            trail.Attachment1 = attachment1
        end
    end
end)

If this helped, mark it correct and upvote (if you have enough rep)! Thanks!

0
Hello Sir, This Worked, Can I Know How You Came to the solution, Thanks! ItzJester2 12 — 5y
1
the reason yours didnt work is due to you changing the haspass variable from false to true when a player has the gamepass. this variable isnt specific to the player so once anyone with that pass logs in now anyone can get the trail. you also never set the "haspass" back to false so even if he leaves until the server closes anyone would be able to have the trail. DinozCreates 1070 — 5y
Ad

Answer this question