Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

2 comments

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.

0

ok, thanks with that.

1 answer

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.

2 comments

0

Ok, I'll try it out, thanks!

0

Ya it still won't work for whatever reason, no errors in output either.

This discussion is preserved as it was. New answers, comments, and votes are closed.