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

Gamepass Works while testing but not in game?

Asked by
DBoi941 57
6 years ago

I think its because of "LocalPlayer" but I am not sure. I am trying to move the TarantulaPet to the players character folder.

local gamePassID = 0000000
local function onPlayerAdded(player)

    local hasPass = false

    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
    end)

    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end

    if hasPass == true then
        player.CharacterAdded:connect(function(character)
            game.ServerStorage:FindFirstChild("TarantulaPet"):Clone().Parent = game.Players.LocalPlayer.Character
        end)
    end
end

Players.PlayerAdded:Connect(onPlayerAdded)
0
Is this in a local script? chomboghai 2044 — 6y

1 answer

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
6 years ago

You don't need to use game.Players.LocalPlayer.Character, because the CharacterAdded event has the character argument passed in already. Even then, this should be a server script, so you can't use LocalPlayer in a server script.

    if hasPass then -- you don't need == true
        player.CharacterAdded:Connect(function(character) -- change connect to Connect
            game.ServerStorage:FindFirstChild("TarantulaPet"):Clone().Parent = character
        end)
    end

Hope this helps! :)

0
Ok i see what you mean. Thank you very much. DBoi941 57 — 6y
Ad

Answer this question