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

Remote Event Issue? Database Not Saving IntValue

Asked by 5 years ago
Edited 5 years ago

My Local Script Inside Screen Gui " Testing " https://i.gyazo.com/dd2417159cc577ed4a0850adb7fdd9cd.png

Inside local script " UpgradClick" - The mouse button down and up are the only code that are associated with give player a cookie...the upgrades add cookies per click....at baseline with no upgrade when the decal cookie image is clicked it gives player 1 cookie....

-- Variables
local cookiev = script.Parent.ckiesv
local rebirthv = script.Parent.rbv
local cookie = script.Parent.cookie
local upg1 = script.Parent.Box.upg1
local plr = game.Players.LocalPlayer
local upg2 = script.Parent.Box.upg2
local upg3 = script.Parent.Box.upg3
local tip = script.Parent.TextLabel
local sug1 = script.Parent.Box.sug1
local rb1 = script.Parent.rb1
local cc = true
local wt = script.Parent.wt

cookie.MouseButton1Down:Connect(function()
    if cc == true then
    cc = false
    cookie.Size = UDim2.new(0,250,0,250)
    plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value + cookiev.Value
    tip.Visible = true
    tip.Text = ("+"..cookiev.Value.." cookies")
    cookie.Rotation = math.random(-30,30)
    tip.TextColor3 = Color3.new(math.random(0,255)/255, math.random(0,255)/255, math.random(0,255)/255)
    wait(script.Parent.wt.Value)
    cc = true
    end
end)

cookie.MouseButton1Up:Connect(function()
    cookie.Size = UDim2.new(0,300,0,300)
    tip.Visible = false
    cookie.Rotation = 0
end)


upg1.MouseButton1Click:Connect(function()
    if plr.leaderstats.Cookies.Value >= 50 then
    plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 50
    cookiev.Value = cookiev.Value + 5
    end
end)

upg2.MouseButton1Click:Connect(function()
    if plr.leaderstats.Cookies.Value >= 150 then
    plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 150
    cookiev.Value = cookiev.Value + 15
    end
end)

upg3.MouseButton1Click:Connect(function()
    if plr.leaderstats.Cookies.Value >= 250 then
    plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 250
    cookiev.Value = cookiev.Value + 25
    end
end)

sug1.MouseButton1Click:Connect(function()
    if plr.leaderstats.Cookies.Value >= 5000 then
    plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 5000
    wt.Value = wt.Value - 0.1
    if wt.Value <= 0 then
        sug1.Visible = false
    end
  end
end)

rb1.MouseButton1Click:Connect(function()
    if plr.leaderstats.Cookies.Value >= 2000000 then
    plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 2000000
    cookiev.Value = cookiev.Value * 1.3
    plr.leaderstats.Rebirths.Value = plr.leaderstats.Rebirths.Value + rebirthv.Value
    end
end)

Whats Inside My Server Script Service ( https://i.gyazo.com/7a165e7345dffa90379fe08a77dc5890.png)

Inside Script " leaderboard"

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CookiesSaveSystem")

function savetablefunc(player)--a table is much more efficient for saving
    local savetable = {
        cookies = player.leaderstats.Cookies.Value,
        rebirths = player.leaderstats.Rebirths.Value
    }
         return savetable
end


game.Players.PlayerAdded:Connect(function(player)

    local clone = script.leaderstats:Clone()--here we clone the files over
    clone.Parent = player

    local save = savetablefunc(player)
    local savedstuff = ds1:GetAsync(player.userId)
    function datapull(player,save) -- here we pull the saved data into the ints we cloned
        player.leaderstats.Cookies.Value = savedstuff.cookies
        player.leaderstats.Rebirths.Value = savedstuff.rebirth
    end
        datapull(player,save)
end)

function savedata(player) --this is just the function to call on leaving 
    local save = savetablefunc(player)
    ds1:SetAsync(player.userId,save)
end

game.Players.PlayerRemoving:Connect(savedata)-- here we save the data on player leaving, you dont need on change its wasteful in most cases


0
I meant more like make a NEW question but i suppose this works. Also post your localscript where the cookies are given, inside seperate LUA brackets above. DinozCreates 1070 — 5y
0
uhhh TheluaBanana 946 — 5y
0
uhhh TheluaBanana 946 — 5y
0
DinozCreates you still there? ultraplage 11 — 5y
View all comments (4 more)
0
yes, ok so ill give you the gist and let you figure the rest out. hold up. DinozCreates 1070 — 5y
0
refresh page updated some thing ultraplage 11 — 5y
0
also yes, just give me the gist and will follow it when i have more time to mess with my game and learn more lua. I didn't expect you to do it for me haha even though would be nice right..Anyways much appreicate the help you been giving me, am learning new things from just chatting with you... ultraplage 11 — 5y
0
Im not good but i have a general enough understanding of data stores and remote events to get you started! DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Add a remote event named CookieEvent into replicated storage. This should work, you'll have to figure out the rest from here. Just replicate what I did and adjust as needed.

Server Script

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CookiesSaveSystem")

function savetablefunc(player)--a table is much more efficient for saving
    local savetable = {
        cookies = player.leaderstats.Cookies.Value,
        rebirths = player.leaderstats.Rebirths.Value
    }
         return savetable
end


game.Players.PlayerAdded:Connect(function(player)

    local clone = script.leaderstats:Clone()--here we clone the files over
    clone.Parent = player
    Cookies = player.leaderstats.Cookies

    local save = savetablefunc(player)
    local savedstuff = ds1:GetAsync(player.userId)
    function datapull(player,save) -- here we pull the saved data into the ints we cloned
        player.leaderstats.Cookies.Value = savedstuff.cookies
        player.leaderstats.Rebirths.Value = savedstuff.rebirth
    end
        datapull(player,save)
    --here we wait for the remote event, then determine what to do
    game.ReplicatedStorage.CookieEvent.OnServerEvent:Connect(function(cookiev)
        Cookies.Value = Cookies.Value + cookiev.Value
    end)
end)

function savedata(player) --this is just the function to call on leaving 
    local save = savetablefunc(player)
    ds1:SetAsync(player.userId,save)
end

game.Players.PlayerRemoving:Connect(savedata)-- here we save the data on player leaving, you dont need on change its wasteful in most cases

Local Script

cookie.MouseButton1Down:Connect(function()
    if cc == true then
    cc = false
    cookie.Size = UDim2.new(0,250,0,250)
    game:GetService("ReplicatedStorage").CookieEvent:FireServer(cookiev)--firing remote event from the client
    tip.Text = ("+"..cookiev.Value.." cookies")
    cookie.Rotation = math.random(-30,30)
    tip.TextColor3 = Color3.new(math.random(0,255)/255, math.random(0,255)/255, math.random(0,255)/255)
    wait(script.Parent.wt.Value)
    cc = true
    end
end)
0
yeah, there is no way im going to know what to script inside "CookieEvent" :( looking at https://developer.roblox.com/api-reference/class/RemoteEvent and just confuzed. ultraplage 11 — 5y
0
This script as is should work correctly as long as you've done exactly what i said. DinozCreates 1070 — 5y
0
so you don't have any code inside CookieEvent? ultraplage 11 — 5y
View all comments (16 more)
0
CookieEvent is a remote event. go into replicated storage, hit the + symbol, and add in a "remote event" name it CookieEvent, DinozCreates 1070 — 5y
0
hahaha omg, i added a script and named it CookieEvent XD ultraplage 11 — 5y
0
Okay added a remoteevent and named it CookieEvent then. I run the game click my cookie decal....but my cookies leaderstat invalue doesn't add cookies once its clicked? ultraplage 11 — 5y
0
On line 28 of the server script add print ("test") below the cookie + cookiev line, tell me if that prints into the output when clicked. DinozCreates 1070 — 5y
0
I clicked the cookie decal twice and here is the output https://i.gyazo.com/a23f8b60a57f38fbf1da8ac6faf616b5.png ultraplage 11 — 5y
0
I did some testing, added some cookies by going into the cookies intvalue just to see if when i click an upgrade and then click the cookie decal my lable show i have 6 cookies per click it does, but doesn't add the cookies to the leaderstats ultraplage 11 — 5y
0
Likely you're gonna have to define cookiev in the server script. DinozCreates 1070 — 5y
0
okay, will reply to this tomorrow if i fixed it or not haha im going to play some game before bed....anyways, thanks again for getting me this far :) ultraplage 11 — 5y
0
i'm not sure what you mean why you say define cookiesv, cookiesv is a seperate intvalue and its only used for the upgrades. The code above like you said before should work as is, but for some reason its not and haven't been able to figure out how to fix it :(... ultraplage 11 — 5y
0
where we put cookiev in the ( ) we pass the value with the remote event, so that is our reference point. somewhere along the line something was done wrong. DinozCreates 1070 — 5y
0
I know we got rid of this code that was in local script when we didn't use the remoteevent "plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value + cookiev.Value" maybe this has something too do with it? ultraplage 11 — 5y
0
i'm thinking the issue is cookiev because, i deleted that from both remote events and my cookies were saved. But, my uprades didn't get saved which is what cookiev and rebirthv are, had to rename the datastore to "CookiesSaveSystemv2" so i could start fresh again...but reverted it back to your code will wait for you opinion on what too do next... ultraplage 11 — 5y
0
Your upgrades didn’t get saved because you haven’t set those up with remote events. The only one set up is the first one. You’ll have to mimic what I’ve done and change the rest to remote events as well. Removing the code was needed, as local script code won’t work for this only a remote event. DinozCreates 1070 — 5y
0
So, the only one setup are my click down cookie value? my cookiev isn't setup? ultraplage 11 — 5y
0
Yeah, this is beyond my scope of lua....think my game is going to be put on hold until i learn more. I appreacite you help thus far and wish me luch on trying to figure this out hehe ultraplage 11 — 5y
0
Good luck! Once you have more practice try and come back here, see if it makes more sense once you have a better fundamental understanding of what is going on. DinozCreates 1070 — 5y
Ad

Answer this question