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

onCharacterLoaded don't work when player joins the game? help

LocalScript inside StarterGui

Checks if the player has game pass and then does the thing, but only works when player resets and not when he joins the game

So if you bought a game pass ( gear ) left the game, rejoined It wouldn't give it to you unless you reset.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local GamePassID = 7411543

function onCharacterLoaded(Character)
  local check = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamePassID)
    if check then
	
 print("this should print when the player joins, but it doesn't pls help")

 end
end
player:GetPropertyChangedSignal("Character"):Connect(onCharacterLoaded)

Again it works when player resets and that good, but not when the player joins.

1 answer

✓ Accepted answer

First, your script is a local script since it has ".LocalPlayer" you'd want a server-sided script instead. Second, get the player when he enters and their character when it spawns

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
--local player = game.Players.LocalPlayer
local GamePassID = 7411543
Players.PlayerAdded:Connect(function(plr) -- this gets the player (for a script and local but I would do script)
	plr.CharacterAdded:Connect(function(character) -- When a character is added, the argument is followed up by the variable "character"
		local check = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, GamePassID)
		if check then 
			print("this should print when the player joins, but it doesn't pls help") 
		end
	end)
end)

2 comments

0

yeah youre right I should do this using script instead

0

You're welcome!

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