So I have been trying to make a gui that you can type promo codes (aka twitter codes) and it would give you a reward but it does not seem to work.
Please could someone help me with this?
Part One
local RS = game:GetService("ReplicatedStorage")
local Codes = {"Cash", "Money", "Code"}
local Event = RS.CodeEvent
script.Parent.EnterButton.MouseButton1Click:Connect(function()
if script.Parent.TextBox.Text == Codes[1] then
print("Event Fired 1")
Event:FireServer(1000, Codes[1])
else
if script.Parent.TextBox.Text == Codes[2] then
print("Event Fired 2")
Event:FireServer(2500, Codes[2])
else
if script.Parent.TextBox.Text == Codes[3] then
print("Event Fired 3")
Event:FireServer(5000, Codes[3])
end
end
end
end)
Part Two
local RS = game:GetService("ReplicatedStorage")
local Event = RS.CodeEvent
Event.OnServerEvent:Connect(function(player, reward, code)
if player:FindFirstChild(code) == nil then
print("Created")
local Redeemed = Instance.new("BoolValue", player)
Redeemed.Name = code
Redeemed.Value = false
if Redeemed == false then
print("Done")
player.leaderstats.Points.Value += reward
Redeemed.Value = true
end
end
end)
2 Likes
Hey there!
First off it is important to know that client scripts can be read into by exploiters, this means anything you put in your local script can be seen by a exploiter with something like dex. However, you can forgo the use of storing the Codes in a local script and instead put them in the server.
I’d use a remote function for this too.
What exactly is the problem here? Are the points not updating or something else if wrong?
2 Likes
I have put the second script in the server script service and yes the points aren’t updating the part where it says, if Redeemed == false then, it stops working and it never even gets to it.
You could probably change the Script from the Server’s Side around a bit, possibly create a else statement if the Code the Player typed is not visible to them:
local RS = game:GetService("ReplicatedStorage")
local Event = RS.CodeEvent
Event.OnServerEvent:Connect(function(player, reward, code)
local CodeCheck = player:FindFirstChild(code)
local Points = player:WaitForChild("leaderstats"):WaitForChild("Points")
if CodeCheck then
if CodeCheck.Value == false then
print("Done")
Points.Value += reward
elseif CodeCheck.Value == true then
print("Player", player, "has already redeemed this code!")
return
end
else
local Redeemed = Instance.new("BoolValue")
Redeemed.Name = code
Redeemed.Value = true
Redeemed.Parent = player
Points.Value += reward
end
end)
2 Likes
local RS = game:GetService("ReplicatedStorage")
local Event = RS.CodeRemoteFunction -- create this or a remote function
script.Parent.EnterButton.MouseButton1Click:Connect(function()
if script.Parent.TextBox.Text ~= "" then
local reward, fail = Event:InvokeServer('twittercode'0)
if reward then
-- what you want the player to see if they have a successful code, like a gui pop in
end
if fail then
script.Parent.TextBox.Text = "Invalid Code!"
end
end)
local Codes = {["Cash"] = {Reward = 1000} , ["Money"] = {Reward = 2500} , ["Code"] = {Reward = 5000}}
local RS = game:GetService("ReplicatedStorage")
local Event = RS.CodeRemoteFunction
local function TwitterCodeManager(player, code)
local reward, fail
if Codes[code] then
local Redeemed = Instance.new("BoolValue")
Redeemed.Parent = player
Redeemed.Name = code
Redeemed.Value = false
if not Redeemed.Value then
player.leaderstats.Points.Value += Codes[code].Reward
Redeemed.Value = true
reward = true
end
else if Codes[code] == nil then
fail = true
end
return reward, fail
end
Event.OnServerInvoke = TwitterCodeManager
1 Like
local RS = game:GetService("ReplicatedStorage")
local Event = RS.CodeRemoteFunction -- create this or a remote function
script.Parent.EnterButton.MouseButton1Click:Connect(function()
if script.Parent.TextBox.Text ~= "" then
local reward, fail = Event:InvokeServer('twittercode'0)
if reward then
-- what you want the player to see if they have a successful code, like a gui pop in
end
if fail then
script.Parent.TextBox.Text = "Invalid Code!"
end
end)
local Codes = {["Cash"] = {Reward = 1000} , ["Money"] = {Reward = 2500} , ["Code"] = {Reward = 5000}}
local RS = game:GetService("ReplicatedStorage")
local Event = RS.CodeRemoteFunction
local function TwitterCodeManager(player, code)
local reward, fail
if Codes[code] then
local Redeemed = Instance.new("BoolValue")
Redeemed.Parent = player
Redeemed.Name = code
Redeemed.Value = false
if not Redeemed.Value then
player.leaderstats.Points.Value += Codes[code].Reward
Redeemed.Value = true
reward = true
end
else if Codes[code] == nil then
fail = true
end
return reward, fail
end
Event.OnServerInvoke = TwitterCodeManager
1 Like