Hey people. Today I decided to make a discord code system that gives the user 500 cash once the code is redeemed. I knew I would need to use like a RemoteEvent or something...
So I wrote this code...
CLIENT SIDE:
frame = script.Parent.Parent.TwitterCodeFrame button = script.Parent closebutton = frame.ImageButton submit = frame.Submit box = frame.CodeBox code = "ROBLOXObby" repstor = game.ReplicatedStorage player = game.Players.LocalPlayer repeat wait(1) until player and player:IsDescendantOf(game.Players) remote = game.ReplicatedStorage.Functions.RemoteEvent button.MouseButton1Click:Connect(function() frame:TweenPosition(UDim2.new(0.205,0,0.12,0)) button.Visible = false end) closebutton.MouseButton1Click:Connect(function() frame:TweenPosition(UDim2.new(1.303,0,0.12,0)) button.Visible = true end) submit.MouseButton1Click:Connect(function() if box.Text == code then submit.Text = "Code redeemed!" remote:FireServer(500) wait(3) submit.Text = "Submit" else submit.Text = "Invalid code!" wait(3) submit.Text = "Submit" end end)
So what that code does is when the correct code is used, it sends the amount of cash the user will receive to the server.
So, I wrote this to intercept the FireServer() function.
--local PointHandler = require(script.Parent.Parent.Functions.PointHandler) --local addpoints = PointHandler.addpoints --local delpoints = PointHandler.delpoints local rep = game.ReplicatedStorage local Settings = require(rep.Settings.ConfigScript) local DataStore = game:GetService("DataStoreService"):GetDataStore("ROBLOX_Obby") local SaveTime = tick() local keyfab = "lb-%s" local admintab = {"ImGeekGrrl", "FreakingHulk"} local remote = game.ReplicatedStorage.Functions.RemoteEvent remote.OnServerEvent:Connect(function(p, ...) local stats = p.leaderstats local cash = stats.Cash.Value cash = cash+... print("Added cash.") end) function checkadmin(p, admins) for _,v in next, admins do if p.Name == v then return true else return false end end end --\\ Auto Save local function Save() for i,v in pairs(game.Players:GetChildren()) do spawn(function() local key=keyfab:format(v.UserId) DataStore:SetAsync(key, {v.leaderstats["Cash"].Value}) print("Successfully saved "..v.leaderstats["Cash"].Value.." in "..v.Name.."'s Credit account!") end) end end --\\ Load game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local cash = Instance.new("NumberValue", leaderstats) cash.Name = "Cash" cash.Value = 0 local key=keyfab:format(player.UserId) local saveValue = DataStore:GetAsync(key) if saveValue ~= nil then cash.Value = saveValue[1] print("Successfully loaded "..player.Name.."'s account!") else cash.Value = 0 DataStore:SetAsync(key, {cash.Value}) print("Successfully made "..player.Name.."'s account!") end player.Chatted:Connect(function(msg) if msg:lower() == "save" then if checkadmin(player, admintab) then Save() print("Saved everyone's stats.") end end end) end) --\\ Save game.Players.PlayerRemoving:Connect(Save) --\\ Auto Save while wait(tonumber(Settings.DataStore.Autosave)) do Save() end
The GUI works okay when I join the game and enter the code. Except the code is supposed to give you 500 cash when redeemed. When I checked my Cash value, it was still at 10,000...
How would I fix this bug?
Thanks,
FreakingHulk14 (FHGDev)