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

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

Asked by
14dark14 167
4 years ago

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

Log in to vote
1
Answered by 4 years ago

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)

0
yeah youre right I should do this using script instead 14dark14 167 — 4y
0
You're welcome! MattyGamin 41 — 4y
Ad

Answer this question