How do I go about putting local scripts on the character?

So I have multiple moveset folders which each contain the localscript needed for a moveset. I want to be able to put the a folder that corresponds to the players chosen moveset inside the players character and have it run.

I already have a datastore for keeping track of what moveset the player has.

Basically, what im trying to do is put local scripts in startercharacterscripts but from a server script, but I then learned that you cant do that so, how do I do this?

Examples of this in other games would be loading the players selected charcters skills in The Strongest Battlegrounds - Roblox

3 Likes

Are you trying to put specific local scripts inside the character via a server script? Sorry if this sounds likes a dumb question but I don’t quite understand your wording.

1 Like

Why don’t you place the local scripts dirrectly on StarterCharacterScripts

4 Likes

He has a datastore that tracks the movesets that the player has. I think he wants to put the moveset that player has selected inside of the their character. Putting them in starterCharacterScripts means that the player would start with every moveset, you could probably disable those movesets though and only enable them when they’re using it.

If he does that, the game would have many backdoors and exploiters could exploit that really bad, unless he has sanity checks on server
side.

That’s why I’m trying to confirm.

1 Like

Couldn’t you just send a table of the moveset data to the client? For instance, you could turn each moveset into a specific number code, then play the entire moveset?

1 Like

I dont want all players to be able to use this script, only people that it applies to

1 Like

Yeah thats what im trying to do

1 Like

@MadMonty_Lead is there a way to do this without having every moveset local script be in startercharacter scripts?

1 Like

I dont understand, what kind of data would be in the table?

1 Like

For example, each moveset represents a number:

1 is for kick, 2 is for punch, 3 is for dancing or something like that, you could make a table that lists all the movesets, then play it afterward:

{1, 2, 1, 2, 3} is just kick, punch, kick, punch then dance. The client only needs to know which moveset represents which number, then you would play it depending on the moveset data you got. If you want to keep the moveset private, then you might have to pass along extra data about it, modify as you wish though!

1 Like

Well, you could probably put a folder under the server script with every moveset and then clone the moveset to the player.

1 Like

I tried that and used the player added and character added events for it but it only works half the time

1 Like

This may not be the best design but it should be pretty easy to implement

So on the server side where you handle data, I would set attributes to the player once the data has been loaded, ie

local data = fetchData()
local movesets = data.movesets
for count, moveset in ipairs(movesets) do
    player:SetAttribute("moveset" .. count, moveset)
end

then on the client you could have some “movesetLoader”

local movesetScripts = "scriptsLocation"
local function hasDataLoaded()
    return player:GetAttribute("moveset1") ~= nil
end
local function onCharacterAdded()
    if not hasDataLoaded() then print("no data yet") end

    local count = 1;
    local currentMoveset = player:GetAttribute("moveset"..count)
    while currentMoveset do
        local src = movesetScripts:FindFirstChild(currentMoveset)
        if not src then
            print("could not find moveset script,", src)
            break
        end

        src:Clone().Parent = workspace;
        count++;
    end
end

-- call onCharacterAdded whenever u know new character has loaded

it doesn’t directly put local scripts in “startercharacterscripts” but I would say it achieves the same goal and is pretty easy to implement some design like this

this does require you to have consistent naming, ie if “punch” is saved as a moveset then you would also need a corresponding script named “punch”

1 Like

Thank you I will try this
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1 Like