Best way to add daily active rewards?

so, I was trying to do daily active rewards then in the middle of code I realized it is not safe at all and really easy to exploit. and I am new at scripting. so I am wondering what’s the best way to do?
This is a local script inside the StarterGui

local MainImageIcon = script.Parent.Parent:WaitForChild("ImageOfGift")

local Template = script.Parent:WaitForChild("ImageButton")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Rewards = require(ReplicatedStorage:WaitForChild("ModuleScript"))

local function GenerateRewardsIcons(setting)

local clone = Template:Clone()

clone.Parent = Template.Parent

clone.Visible = true

clone.MouseButton1Click:Connect(function()

print("Menolia")

end)

end

for i,v in pairs(Rewards) do

GenerateRewardsIcons()

end

MainImageIcon.MouseButton1Click:Connect(function()

Template.Parent.Visible = not Template.Parent.Visible

end)

for i,v in pairs(module) do 
GenerateRewardsIcons()
end

I can Use remote emotes but there is 12 rewards and creating 12 different remote events seems ugly way to do it
so. Which way should I follow?

There no connection with any remote event?

1 Like

… I literally said

This means I didn’t used remotes yet and I don’t want to because it seems ugly and hard way to do it

1 Like

so you want just send information to the client?

You can do it in server side? And send from remote event all data to know?

If I understood it right, you’re asking for a way to prevent this script from being exploited.


You should do something like this-

clone.MouseButton1Click:Connect(function()
  -- Fire a remote function to the server (Ex: ServerAwards is the name)
 -- Using a remote function will be useful in the future when you want to display a "Claimed!" GUI or something
end)

Server

ServerAwards.OnServerInvoke = function()
 -- Validate that it has been 24 hrs from their previous award (you might have to use datastore for this one)

 -- Code to give the award

 -- Return true if they are eligible and false if they aren't
end)

EDIT: Wrong reply, @AngelNotLikeYou

2 Likes

and do you think I know how to do that? like then why I did ask the question come on?
I can send data to server with remotes But adding 12 remote events not a good way how can I do it with just a remote event

well this function will connect when a player click one of the reward. so, how do I detect player clicked the 2nd award not 1st. the codes you give only would work if there was only 1 reward right?

You do this:

--Fire with arguments 1 for the first awards clicked
AwardsServer:FireServer(1)

Then you create a code in the server side and you are done

so I am still creating 12 different remote events? or am I understanding wrong?
like

Reward1.OnMouse1Clicked:Connect(Function()
AwardsServer:FireServer(1)

Reward2.OnMouse1Clicked:Connect(Function()
AwardsServer:FireServer(2)
Reward3.OnMouse1Clicked:Connect(Function()
AwardsServer:FireServer(3)
Reward4.OnMouse1Clicked:Connect(Function()
AwardsServer:FireServer(4)
RewardN.OnMouse1Clicked:Connect(Function()
AwardsServer:FireServer(N)

I understand, you want to check if the player took the first awards?

I want to check if player claimed the 1st reward or 2nd or 3rd without using 12 different FireServer and OnMouse1Clicked event

if you didn’t know, you can detect if the player clicked even if you are server-side so hackers have no chance of bypassing the check Doing MouseButton1Down

So, how knowing that excatly solves using 12 different function problem?

Create a server script and put it in the interface:

for i,v in pairs(interface.Awards:GetChildren()) do
    --The name of the button is like Awards1
	if string.find(v.Name,"Awards") then
        --When the player clicked
		v.MouseButton1Down:Connect(function()
            -- Verify if he don't clicked it with color (when green)
			if v.BackgroundColor3 == Color3.new(0.333333, 0.666667, 0) then
                --Give him the awards to the player with the name of the button
				GivePlayerAward(player,v.Name)
                --Put the color gray for say that the player clicked
				v.BackgroundColor3 = Color3.new(0.811765, 0.811765, 0.811765)
			end
		end)
	end
end
1 Like

I am getting brain freezes from this conversation, you dont need to use 12 remote events, remote events can pass arguments, so just use an array with the rewards and index it with a number that’s sent from server using the remote

1 Like

I didn’t put any remote event in my script?

Sorry my bad, that reply was made for this overall conversation, not just your reply

I am getting brain freezes when Scripters act and talk like all new scripters knows everything about how to use things I don’t know how to create an array and use it! I know I sound like stupid but I literally said like 4 times I am a new scripter. but Thanks for advice I really appreciate for it

I even didn’t know I could use arrays for StarterGui things.

I used arrays for creating a shop and for npc kill rewards But never Used them in a StarterGui

I have the answer but I think I defined it wrong

1 Like