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

Why won't this script work?

Asked by 8 years ago

I've tried to make a Data Store script, where you save the colors of a bring. However, the colors won't load on the part. Aaaand, when it checks if the player has loaded, nothing happens. (I've used tostring, mind you)

However, when i use the script, it shows no error (Btw, i made an update script too)

Aaand this is in a normal script, not a local script

(PS: Chest does NOT mean Torso!, Its a completely different model in the player that i'm indexing)

If i'm doing something wrong, let me know!

This is the save script

local DataStore = game:GetService("DataStoreService"):GetDataStore("NicuWolfSlot1")
local player = script.Parent.Parent

local colorstosave = {
player.Character.Chest.Body.BrickColor,
player.Character.Chest.Chest.BrickColor,
player.Character.Chest.Neck.BrickColor,
player.Character.Chest.Tail1.BrickColor,
player.Character.Chest.Tail2.BrickColor,
player.Character.Chest.Tail3.BrickColor,
player.Character.Chest.bodyfrontA.BrickColor,
player.Character.Chest.bodyfrontB.BrickColor,
player.Character.Chest.ear1.BrickColor,
player.Character.Chest.ear1p2.BrickColor,
player.Character.Chest.ear1p3.BrickColor,
player.Character.Chest.ear2.BrickColor,
player.Character.Chest.ear2p2.BrickColor,
player.Character.Chest.ear2p3.BrickColor,
player.Character.Chest.head.BrickColor,
player.Character.Chest.muzzle1.BrickColor,
player.Character.Chest.muzzle2.BrickColor,

player.Character.Leg1.BackLLeg.BrickColor,
player.Character.Leg1.FrontRpaw.BrickColor,
player.Character.Leg1.FrontRLeg.BrickColor,
player.Character.Leg1.ShoulderRback.BrickColor,
player.Character.Leg1.ShoulderLfront.BrickColor,
player.Character.Leg1.BackRpaw.BrickColor,

player.Character.Leg2.BackRLeg.BrickColor,
player.Character.Leg2.FrontLpaw.BrickColor,
player.Character.Leg2.FrontLLeg.BrickColor,
player.Character.Leg2.ShoulderLback.BrickColor,
player.Character.Leg2.ShoulderRfront.BrickColor,
player.Character.Leg2.BackLpaw.BrickColor,
}


local Colors = {"Institutional white","Really black","Reddish brown","Dark stone grey","Dark orange","Black",
    "Brick yellow","Nougat","Cool yellow","Bright yellow","Pastel yellow",
    "Medium stone grey","Mid gray"}

Body = tostring(player.Character.Chest.Body.BrickColor)
Chest = tostring(player.Character.Chest.Chest.BrickColor)
Neck = tostring(player.Character.Chest.Body.BrickColor)
Tail1 = tostring(player.Character.Chest.Body.BrickColor)
Tail2 = tostring(player.Character.Chest.Body.BrickColor)
Tail3 = tostring(player.Character.Chest.Body.BrickColor)
bodyfrontA = tostring(player.Character.Chest.bodyfrontA.BrickColor)
bodyfrontB = tostring(player.Character.Chest.bodyfrontB.BrickColor)
ear1 = tostring(player.Character.Chest.ear1.BrickColor)
ear1p2 = tostring(player.Character.Chest.ear1p2.BrickColor)
ear1p3 = tostring(player.Character.Chest.ear1p3.BrickColor)
ear2 = tostring(player.Character.Chest.ear2.BrickColor)
ear2p2 = tostring(player.Character.Chest.ear2p2.BrickColor)
ear2p3 = tostring(player.Character.Chest.ear2p3.BrickColor)
head = tostring(player.Character.Chest.head.BrickColor)
muzzle1 = tostring(player.Character.Chest.muzzle1.BrickColor)
muzzle2 = tostring(player.Character.Chest.muzzle2.BrickColor)
BackLLeg = tostring(player.Character.Leg1.BackLLeg.BrickColor)
FrontRpaw = tostring(player.Character.Leg1.FrontRpaw.BrickColor)
FrontRLeg = tostring(player.Character.Leg1.FrontRLeg.BrickColor)
ShoulderRback = tostring(player.Character.Leg1.ShoulderRback.BrickColor)
ShoulderLfront = tostring(player.Character.Leg1.ShoulderLfront.BrickColor)
BackRpaw = tostring(player.Character.Leg1.BackRpaw.BrickColor)
BackRLeg = tostring(player.Character.Leg2.BackRLeg.BrickColor)
FrontLpaw = tostring(player.Character.Leg2.FrontLpaw.BrickColor)
FrontLLeg = tostring(player.Character.Leg2.FrontLLeg.BrickColor)
ShoulderLback = tostring(player.Character.Leg2.ShoulderLback.BrickColor)
ShoulderRfront =tostring (player.Character.Leg2.ShoulderRfront.BrickColor)
BackLpaw = tostring(player.Character.Leg2.BackLpaw.BrickColor)


local viewkey = "Colorsfor"..player.userId


game.Players.PlayerRemoving:connect(function()


        local Tosave = {Chest,Neck,Tail1,Tail2,Tail3,bodyfrontA,bodyfrontB
        ,ear1,ear1p2,ear1p3,ear2,ear2p2,ear2p3,head,muzzle1,muzzle2,BackLLeg,FrontRpaw,FrontRLeg,
        ShoulderRback,ShoulderLfront,BackRpaw,BackRLeg,FrontLpaw,FrontLLeg,ShoulderLback,
        ShoulderRfront,BackLpaw,Body}

        DataStore:SetAsync(viewkey,Tosave)


        print ("Saved!")

end)
0
What exactly isn't working? You didn't explain that, please explain further TurboFusion 1821 — 8y
0
Done and done :P CrammelApple 50 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Based on the "player = script.Parent.Parent" line, this is a LocalScript. Datastores cannot be accessed from LocalScripts. (Even if they did, you'd want to check the argument of PlayerRemoving to make sure that it's "player" that's leaving the game and not someone else)

Also, your script doesn't use colorstosave or Colors - why bother defining them?

Ad

Answer this question