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

Why doesn't this script work?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I have this game I'm trying to remake famous and this save script isn't working?It doesn't save data

Game: http://www.roblox.com/Galactic-Front-ALPHA-TELEPORT-GLITCH-PATCHED-place?id=178549718

Not Working Script:

debounce=false
function Save()
    if debounce==false then
        debounce=true 
        player=game.Players.LocalPlayer
        script.Parent.Text="Saving..."
        player:WaitForDataReady()
        player:SaveNumber("Credit", player.Credit.Value)
        inv=player:FindFirstChild("Inventory")
        for saveinv=1,8 do
            if inv~=nil then
                saveslot=inv:FindFirstChild("Slot"..saveinv)
                if saveslot~=nil then
                    player:SaveString(("Slot"..saveinv), saveslot.Value)
                end
            end
        end
        wait(2)
        script.Parent.Text="Save"
        debounce=false
    end
end


script.Parent.MouseButton1Down:connect(Save)
0
Please put your code into the Code Block. It will really help me answer your question. bobafett3544 198 — 10y
0
There epicfatcookie 0 — 10y
0
Thanks. bobafett3544 198 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

1) I recommend using Data Stores, Data Persistence is outdated, here's the Data Store wiki page 2) You can't access Data Persistence or Data Stores through LocalScripts, you need a normal script.

Here's your revamped script:

local player = script.Parent.Parent.Parent.Parent.Parent.Parent --assuming this button is in a TextButton, in a ScreenGui, this is how to find player
local creditSaves = game:GetService("DataStoreService"):GetDataStore("creditSaves")
local invSaves = game:GetService("DataStoreService"):GetDataStore("invSaves")
local credits = player.Credit.Value
local inv = player:FindFirstChild("Inventory")
local deb = false
script.Parent.MouseButton1Click:connect(function()
if not deb and player:WaitForDataReady() then
deb = true
script.Parent.Text = "Saving..."
creditSaves:SetAsync(player.Name.." credits", credits)
for saveInv = 1, 8 do
if inv then
saveSlot = inv:FindFirstChild("Slot"..saveInv)
if saveSlot then
invSaves:SetAsync(player.Name.." inventory", saveInv)
end
end
end
script.Parent.Text = "Save"
end
end)

That should work.

0
Alright, Testing it. epicfatcookie 0 — 10y
0
Not to be rude or anything, But could you make the script for me? epicfatcookie 0 — 10y
0
Lol ok. bobafett3544 198 — 10y
0
xP epicfatcookie 0 — 10y
View all comments (16 more)
0
But my game is diffrent, Go play it and see...The save has to save GUI weapons/guns/helmets and stuff epicfatcookie 0 — 10y
0
Ok. I'll check it out after school. bobafett3544 198 — 10y
0
Okay. epicfatcookie 0 — 10y
0
If you like that answer, please mark it as accepted. It helps me out. bobafett3544 198 — 10y
0
I put that script in a regular script and doesn't work, Do I put n a local script? epicfatcookie 0 — 10y
0
No, it's supposed to be in a regular script. I noted that the script was made if it were in a TextButton, in a ScreenGui, in StarterGui. Unless you didn't put it in that order, or I made a mistake, then it should work. bobafett3544 198 — 10y
0
Its a TextButton in a frame and that frame is in another frame, THEN comes the screen GUI epicfatcookie 0 — 10y
0
Wait, so it's TextButton>Frame>Frame>ScreenGui? bobafett3544 198 — 10y
0
Mhm epicfatcookie 0 — 10y
0
Ok. bobafett3544 198 — 10y
0
So........ epicfatcookie 0 — 10y
0
Sorry, I've been working on other projects. I'll start on yours as soon as I get home from school. bobafett3544 198 — 10y
0
Okay, :P epicfatcookie 0 — 10y
0
Its been a day, Done yet? :P epicfatcookie 0 — 10y
0
Not yet bobafett3544 198 — 10y
0
Its been soooooooo long, Done yet? :L epicfatcookie 0 — 10y
Ad

Answer this question