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 make the startercharacter change via a script?

--variables
local marketplaceservice = game:GetService("MarketplaceService") 
local Luigi = game.Lighting.StarterCharacter
local player = game.Players.LocalPlayer
local gamepass = 9693560

script.Parent.MouseButton1Click:Connect(function() --starts all this up when they click
    marketplaceservice:PromptGamePassPurchase(player, gamepass) --sends them the purchase
    marketplaceservice.PromptGamePassPurchaseFinished:Connect(function(player, gamepass, wasPurchased) -- wasPurchased is for whether or not the player purchased the game pass
        if wasPurchased == true then 
                game.StarterPlayer.StarterCharacter:Destroy() --destroys the normal startercharacter
                Luigi.Parent = game.StarterPlayer --adds the new startercharacter
        else
            print("Did not buy gamepass!")
        end
    end)
end)

localscript in texbutton. works but there's an output error!

08:51:25.200 - StarterCharacter is not a valid member of StarterPlayer

4 comments

0

Storing things in lighting is an outdated practice. You should be storing in server storage or replicated storage. If that is a local script it then the storage should be replicated. Pretty sure. That won’t solve it but yeah.

0

ok

0

Which replicated?? First or storage

0

No, ReplicatedFirst is generally used for things like loading screens since those instances are the first ones replicated to the client. For long term assets use ReplicatedStorage.

1 answer

I have done this so many times in a game with custom rig, but it only works in server side script. Make sure you destroy the old StarterCharacter everytime you load a new cause anyone will spawn as it. In your case you will have to use remote event to set that.

Here is my exemple in a server script:

game.Players.CharacterAutoLoads = false
-- disable automatic char loading when playerAdded

local Baby = game.ServerStorage.Baby:Clone()
Baby.Name = "StarterCharacter"
if game.StarterPlayer:FindFirstChild("StarterCharacter") then
	game.StarterPlayer.StarterCharacter:Destroy()
end
Baby.Parent = game.StarterPlayer
player:LoadCharacter()

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