#Set model using modules

1 messages · Page 1 of 1 (latest)

flat island
#

Need help getting a script to get the model from a modulescript, then apply it to the player
also sometimes it looks like the script just isn't working in the first place

#

CharacterChangeHandler

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local changeCharacterEvent = ReplicatedStorage:WaitForChild("ChangeCharacterEvent")
local MagicalGirls = require(ReplicatedStorage.ModuleScripts:WaitForChild("MagicalGirls"))

-- Function to apply character appearance to a player
local function applyCharacter(player, characterKey)
    -- Get character data from module
    local characterData = MagicalGirls[characterKey]
    if not characterData then
        warn("Character not found:", characterKey)
        return false
    end
    
    local templateModel = characterData.model
    if not templateModel then
        warn("Template model not found:", characterData.model)
        return false
    end
    
    -- Get player character
    local character = player.character
    if not character then
        warn("Player character not found")
        return false
    end
    
    
    if templateModel and character then
        local oldcharacter = character
        local newcharacter = templateModel:Clone()
        newcharacter:SetPrimaryPartCFrame(oldcharacter.PrimaryPart.CFrame)
        character = newcharacter
        newcharacter.parent = workspace
        if character then
            print("Applied character appearance for", player.Name, "-", characterData.name)
            return true
        end
    end
    
    return false
end

-- Handle event from client
changeCharacterEvent.OnServerEvent:Connect(function(player, characterKey)
    applyCharacter(player, characterKey)
end)

print("Character Changer Loaded")
#

Module: MagicalGirls

local models = game.ReplicatedStorage.Models.MagicalGirls
local witches = require(script.Parent.Witches)

local girls = {
    kyoko = {
        name = "Kyoko",
        model = models.Kyoko,
        witch = witches.kyoko,
    },
    
    sayaka = {
        name = "Sayaka",
        model = models.Sayaka,
        witch = witches.sayaka,
    },
    
    --mami = {
    --    name = "Mami",
    --    model = models.Mami,
    --    witches = witches.mami,
    --},
    
}

return girls