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

This still won't work inside the game, but will in studio?

Asked by 5 years ago
Edited 5 years ago

I have Filtering Enabled on and I got this code fixed by someone before, but it still won't work for whatever reason, could someone please help?

Client:

local codes = script.Parent.Parent.Codes -- location of the codes
local ds = game:GetService("DataStoreService")
local store = ds:GetDataStore("CodeSave")


script.Parent.MouseButton1Down:Connect(function()
    if script.Parent.Parent.codeBox.Text == "Alpha" then
        if codes.Alpha.Value == true then
            script.Parent.Parent.codeBox.Text = "Already Redeemed!"
        end
        if codes.Alpha.Value == false then
            codes.Alpha.Value = true
            game.ReplicatedStorage.GiveMoney:FireServer()
            script.Parent.Parent.codeBox.Text = "Redeemed!"
        end
    end
end)

Server:

game.ReplicatedStorage.GiveMoney.OnServerEvent:connect(function(player)
    local codes = game.StarterGui.CodeSystem.RedeemArea.Codes
    player.leaderstats.Credits.Value = player.leaderstats.Credits.Value +        
        codes.Alpha.Reward.Value
end)

Don't mind the datastore part, I'm working on that still.

0
Just a heads up, DataStores can only be accessed from the Server. You have it started in your clients code and that won't work. Crazycat4360 115 — 5y
0
ok, thanks with that. K1ng_Phant0m 13 — 5y

1 answer

Log in to vote
0
Answered by
T0XN 276 Moderation Voter
5 years ago
Edited 5 years ago

Right off the bat, I noticed that you accessed StarterGui when PlayerGui should have been accessed instead. When the game runs, the objects within StarterGui get cloned and moved to the PlayerGui of all the players on the server.

Made some improvements to the structure of your if statements:

CLIENT:

local rs = game:GetService("ReplicatedStorage")
local ds = game:GetService("DataStoreService")
local store = ds:GetDataStore("CodeSave")

local codes = script.Parent.Parent.Codes
local cbText =  script.Parent.Parent.codeBox.Text

script.Parent.MouseButton1Down:Connect(function()
    if cbText  == "Alpha" and codes.Alpha.Value then
            cbText  = "Already Redeemed!"
        if not codes.Alpha.Value then
            codes.Alpha.Value = true
            rs.GiveMoney:FireServer()
            cbText  = "Redeemed!"
        end
    end
end)

The real issue is down in the server code.

SERVER:

local rs = game:GetService("ReplicatedStorage")

rs.GiveMoney.OnServerEvent:Connect(function(player)
    local codes = player:WaitForChild("PlayerGui").CodeSystem.RedeemArea.Codes
    player.leaderstats.Credits.Value = player.leaderstats.Credits.Value +        
        codes.Alpha.Reward.Value
end)

Hope this answered your question, but if you're still having issues let me know. Also, if you're getting any errors in the output, I'd like to know what they are.

0
Ok, I'll try it out, thanks! K1ng_Phant0m 13 — 5y
0
Ya it still won't work for whatever reason, no errors in output either. K1ng_Phant0m 13 — 5y
Ad

Answer this question