Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Gamepass Works while testing but not in game?

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)

1 comment

0

Is this in a local script?

1 answer

✓ Accepted answer

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! :)

1 comment

0

Ok i see what you mean. Thank you very much.

This discussion is preserved as it was. New answers, comments, and votes are closed.