Heya!
I’m struggling to figure out how i can change the image button’s image. Normally this would be easy but i am using remote events which makes it 100x more difficult
Server Code:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.ClaimReward
-- Detect when the player joins the game
game.Players.PlayerAdded:Connect(function(player)
-- Define your rewards, locally this time
local Rewards = {
{
Name = "1st",
Time = 1, --120,
Coins = 100,
Reached = false,
Claimed = false,
},
{
Name = "2nd",
Time = 2, --180, -- 1200s = 20 minute,
Coins = 200,
Reached = false,
Claimed = false,
},
{
Name = "3rd",
Time = 3,--300, -- 1200s = 20 minute,
Coins = 200,
Reached = false,
Claimed = false,
},
{
Name = "4th",
Time = 4, --600, -- 1200s = 20 minute,
Coins = 500,
Reached = false,
Claimed = false,
},
{
Name = "5th",
Time = 5, --720, -- 1200s = 20 minute,
Coins = 800,
Reached = false,
Claimed = false,
},
{
Name = "6th",
Time =6, --780, -- 1200s = 20 minute,
Coins = 900,
Reached = false,
Claimed = false,
},
{
Name = "7th",
Time =7, --900, -- 1200s = 20 minute,
Coins = 1000,
Reached = false,
Claimed = false,
},
{
Name = "8th",
Time =8, --1200, -- 1200s = 20 minute,
Coins = 200,
Reached = false,
Claimed = false,
},
{
Name = "9th",
Time =9, --1500, -- 1200s = 20 minute,
Coins = 0,
Gems = 50,
Reached = false,
Claimed = false,
},
{
Name = "10th",
Time =10, --1800, -- 1200s = 20 minute,
Coins = 2500,
Gems = 125,
Pet = "Test",
Reached = false,
Claimed = false,
},
{
Name = "11th",
Time = 11, --2100, -- 1200s = 20 minute,
Coins = 5000,
Gems = 500,
Reached = false,
Claimed = false,
},
{
Name = "12th",
Time =12, --300, -- 1200s = 20 minute,
Coins = 10000,
Gems = 750,
Pet = "Test 2",
Reached = false,
Claimed = false,
},
}
-- Detect when the remote is fired from a client
RemoteEvent.OnServerEvent:Connect(function(remotePlayer, rewardName)
if remotePlayer ~= player then return end
for i, v in ipairs(Rewards) do
if v.Name == rewardName and v.Reached then -- If the reward is found and it is reached
if not v.Claimed then -- Check if it was claimed already
player.leaderstats.Coins.Value += v.Coins
v.Claimed = true
if v.Gems then
player.leaderstats.Gems.Value += v.Gems
v.Claimed = true
end
if v.Pet then
print(v.Pet)
v.Claimed = true
end
end
end
end
end)
-- Initialize their playtime. Note; I'm using seconds in this example, but feel free to use minutes.
local playerPlaytime = 0
-- Every one second
while true and wait(1) do
-- Add a second to their playtime
playerPlaytime += 1
-- Unlock rewards if playerPlaytime is enough
for i, v in ipairs(Rewards) do
if v.Time == playerPlaytime then
v.Reached = true
break
end
end
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Module = require(game:GetService("ReplicatedStorage"):WaitForChild("Uimodule"))
local RemoteEvent = ReplicatedStorage.ClaimReward
--// Animate \\ --
Module.AnimateButton(script.Parent:WaitForChild("Rewards").a.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").b.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").c.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").d.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").e.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").f.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").g.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").h.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").i.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").j.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").k.Vector)
Module.AnimateButton(script.Parent:WaitForChild("Rewards").l.Vector)
--// Claim Rewards \\--
local ButtonsHolder = script.Parent:WaitForChild("Rewards")
ButtonsHolder.a.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("1st")
end)
ButtonsHolder.b.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("2nd")
end)
ButtonsHolder.c.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("3rd")
end)
ButtonsHolder.d.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("4th")
end)
ButtonsHolder.e.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("5th")
end)
ButtonsHolder.f.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("6th")
end)
ButtonsHolder.g.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("7th")
end)
ButtonsHolder.h.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("8th")
end)
ButtonsHolder.i.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("9th")
end)
ButtonsHolder.j.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("10th")
end)
ButtonsHolder.k.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("11th")
end)
ButtonsHolder.l.Vector.MouseButton1Click:Connect(function()
RemoteEvent:FireServer("12th")
end)
Thanks!