i am trying to make a shop but is there a way to prevent when the player clicks the previous button and it wont throw an error like this
16:27:31.458 - Episode 0 is not a valid member of Folder
16:27:31.461 - Stack Begin
16:27:31.462 - Script 'ServerScriptService.Server-Scripts.Scripts.ChangePosition', Line 24
16:27:31.463 - Stack End
here is the code [CURRENT]
game.ReplicatedStorage["ReplicatedStorage Stuff"]["RemoteFunctions"].Call.OnServerInvoke = function(plr, String)
if String == "Increase" then
local PlayerGui = plr:WaitForChild("PlayerGui")
local ShopInfo = PlayerGui:WaitForChild("ShopInfo")
local CostName = ShopInfo.EpisodeCost.EpisodeName
local EpisodeName = ShopInfo.EpisodeName.EpisodeName
plr.Stats.Values.CurrentNumber.Value = plr.Stats.Values.CurrentNumber.Value + 1
local EpisodeValue = plr.Stats.Season1["Episode "..plr.Stats.Values.CurrentNumber.Value]
if EpisodeValue.Value == true then
ShopInfo.Status.TextButton.Text = "Play!"
elseif EpisodeValue.Value == false then
ShopInfo.Status.TextButton.Text = "Buy!"
end
CostName.Text = workspace.Background.ShopStuff["Episode "..plr.Stats.Values.CurrentNumber.Value].Values.Cost.Value.." Coins"
EpisodeName.Text = workspace.Background.ShopStuff["Episode "..plr.Stats.Values.CurrentNumber.Value].Values["Episode Name"].Value
plr.Stats.Values.CurrentEpisode.Value = "Episode "..plr.Stats.Values.CurrentNumber.Value
return "Episode "..plr.Stats.Values.CurrentNumber.Value
elseif String == "Decrease" and plr.Stats.Values.CurrentNumber.Value <= 2 then
local PlayerGui = plr:WaitForChild("PlayerGui")
local ShopInfo = PlayerGui:WaitForChild("ShopInfo")
local CostName = ShopInfo.EpisodeCost.EpisodeName
local EpisodeName = ShopInfo.EpisodeName.EpisodeName
plr.Stats.Values.CurrentNumber.Value = plr.Stats.Values.CurrentNumber.Value - 1
local EpisodeValue = plr.Stats.Season1["Episode "..plr.Stats.Values.CurrentNumber.Value]
if EpisodeValue.Value == true then
ShopInfo.Status.TextButton.Text = "Play!"
elseif EpisodeValue.Value == false then
ShopInfo.Status.TextButton.Text = "Buy!"
end
CostName.Text = workspace.Background.ShopStuff["Episode "..plr.Stats.Values.CurrentNumber.Value].Values.Cost.Value.." Coins"
EpisodeName.Text = workspace.Background.ShopStuff["Episode "..plr.Stats.Values.CurrentNumber.Value].Values["Episode Name"].Value
plr.Stats.Values.CurrentEpisode.Value = "Episode "..plr.Stats.Values.CurrentNumber.Value
return "Episode "..plr.Stats.Values.CurrentNumber.Value
end
end