Difficulty Chart Obby: How can I fix this script to make part of the shop functional?

local rs = game:GetService("ReplicatedStorage")

local End = rs.End
local paydeb = true

local jpcb = game:GetService("ReplicatedStorage").RemoteEventFolder.jpcb
local spcb = game:GetService("ReplicatedStorage").RemoteEventFolder.spcb
local mpcb = game:GetService("ReplicatedStorage").RemoteEventFolder.mpcb

jpcb.OnServerEvent:Connect(function(player)
	if paydeb == true then
		if player.leaderstats.Coins.Value >= 200 then
			paydeb = false
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 200
		end
	end
end)

End.OnServerEvent:Connect(function(player)
	if paydeb == false then
		paydeb = true
	end
end)



game.Players.PlayerAdded:Connect(function(player)
	while true do
		if paydeb == false then
		
			local shop = player:WaitForChild("PlayerGui").Shop.Shadow
			local sframe = shop.Frame.ScrollingFrame

			local jump = sframe.GravityPot.CoinsButton
			local speed = sframe.SpeedPot.CoinsButton
			local mixed = sframe.MixedPot.CoinsButton
			
			local toggle = player.PlayerGui:WaitForChild("EffectToggle").Shadow
			
			jump.TextColor3 = Color3.new(0.784314, 0.784314, 0.784314)
			jump.BackgroundColor3 = Color3.new(0.403922, 0.403922, 0.403922)
			jump.Text = "Effect Active"

			speed.TextColor3 = Color3.new(0.784314, 0.784314, 0.784314)
			speed.BackgroundColor3 = Color3.new(0.403922, 0.403922, 0.403922)
			speed.Text = "Effect Active"
			
			mixed.TextColor3 = Color3.new(0.784314, 0.784314, 0.784314)
			mixed.BackgroundColor3 = Color3.new(0.403922, 0.403922, 0.403922)
			mixed.Text = "Effect Active"
			
			toggle.Visible = true
			
		elseif paydeb == true then
			
			local shop = player:WaitForChild("PlayerGui"):WaitForChild("Shop").Shadow
			local sframe = shop.Frame.ScrollingFrame
			
			local toggle = player.PlayerGui:WaitForChild("EffectToggle").Shadow
			
			local jump = sframe.GravityPot.CoinsButton
			local speed = sframe.SpeedPot.CoinsButton
			local mixed = sframe.MixedPot.CoinsButton
			
			jump.TextColor3 = Color3.new(0.498039, 0.498039, 0.498039)
			jump.BackgroundColor3 = Color3.new(1, 0.717647, 0)
			jump.Text = "200 Coins"

			speed.TextColor3 = Color3.new(0.498039, 0.498039, 0.498039)
			speed.BackgroundColor3 = Color3.new(1, 0.717647, 0)
			speed.Text = "300 Coins"

			mixed.TextColor3 = Color3.new(0.498039, 0.498039, 0.498039)
			mixed.BackgroundColor3 = Color3.new(1, 0.717647, 0)
			mixed.Text = "350 Coins"
			
			toggle.Visible = false
			
		end
		wait(.1)
	end
	
end)

Above is server side script and below is the client script.

local jpcb = game:GetService("ReplicatedStorage").RemoteEventFolder.jpcb
local spcb = game:GetService("ReplicatedStorage").RemoteEventFolder.spcb
local mpcb = game:GetService("ReplicatedStorage").RemoteEventFolder.mpcb

jumppotcoinsbuy.MouseButton1Click:Connect(function()
	jpcb:FireServer(player)
end)

I’m trying to make a potion effect shop. It takes away the coins just fine but the script is lengthy and I can’t figure out how to give the correct effect to the player.

This is readability and shouldn’t fix your code but

Your breaking the DRY rule. First you assigned the replicatedstirage variable and do not use them. Second, you are directly defining the folder and remotes without even waiting for it,
Cleaner code

local rs = game:GetService("ReplicatedStorage")

local End = rs.End
local paydeb = true

local remoteEventFolder = rs:WaitForChild("RemoteEventFolder")
local jpcb = remoteEventFolder:WaitForChild("jpcb")
local spcb = remoteEventFolder:WaitForChild("spcb")
local mpcb = remoteEventFolder:WaitForChild("mpcb")

Also, what are these nonsensical names even mean?

1 Like

LOL. Thanks for the feedback. JPCB means jump potion coins buy which is just the event when somebody buys a jump potion. jump boost*

1 Like

ok

1 Like