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

How do I get this script to run when a character is added instead of a player added?

Alright, 5th try's the charm. Can't be ignored 5 times in a row across 10 hours, right?

local ID = nosneaks
local MLGS = {"ihab123432gamer", "eleutherios", "Erik199875", "iiTHECOOLZ", "flyerbram002", "TrulyRev", "MrCrutuBringer"}
local GUIName = {"VSS", "SVD", "MainPicker", "Back2"} 

local function FindPlayer(Plr)
    for Num, Pler in pairs(MLGS) do
        if Pler == Plr then
            return true
        end
    end
end

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:Connect(function(character)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, ID) or FindPlayer(Player.Name) then
            for Num, TextButton in pairs(GUIName) do
                if game:GetService("ServerStorage"):FindFirstChild(TextButton) then
                    game:GetService("ServerStorage")[TextButton]:Clone().Parent = Player.PlayerGui.pickweap.Main:WaitForChild("RussianWeaps")
                end
            end
        end
        for Num, TextButton in pairs(GUIName) do
            if Player.PlayerGui.pickweap.Main.RussianWeaps:FindFirstChild(TextButton) == nil then
                if game:GetService("ServerStorage"):FindFirstChild(TextButton) then
                        game:GetService("ServerStorage")[TextButton]:Clone().Parent = Player.PlayerGui.pickweap.Main:WaitForChild("RussianWeaps")
                    end
                end
            end
        end)
    end)

this script gives people with a gamepass and some of my freinds a set of guis, this part works fine. But, as soon as they die, the gui doesn't appear. I know that this is because I used PlayerAdded, but I don't know how to change it to CharacterAdded, which I tried to add as you can see but the problem still persists. Please explain what I've done wrong and fix my script, I've never used MarketPlaceService before so I'm really new to this

1 comment

0

Sorry but i couldnt find the issue. I tested the script and it all worked.

1 answer

Are you testing your script inside Roblox Studio? If so, testing in Play Solo mode in Roblox Studio, sometimes the player loads too fast, so the event isn't fired. To fix it, either create a proper local server or add a function to the event and loop through the players to not miss any of them. Example:

function onPlayerAdded(player)
--Codes here
end

for _, player in pairs(game.Players:GetPlayers()) do --looping through the players list
    onPlayerAdded(player)
end

game.Players.PlayerAdded:Connect(onPlayerAdded) -- attaching the function to the event

For the CharacterAdded event, you can also do the same.

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