Difficulty Chart Obby: How can I reduce this script?

The second script in your reply is for checkpoints, probably.

1 Like

TeleportedStage:GetPropertyChangedSignal(“Value”):Connect(function()
num.Text = TeleportedStage.Value
end)

It doesn’t work for some reason assuming this is the line you meant.

1 Like

I meant this line at the beginning of the script.

num.Text = TeleportedStage.Value
1 Like

What do you mean? (characters)

1 Like

What this script does? I think its for checkpoints but it doesnt look very good.

1 Like

I adjusted all of the text to teleportedstage but it still teleports you to stage when you die.

1 Like

You should’ve not done that. Only replace Stage to TeleportedStage in the script where you teleport character to checkpoint on respawn.

1 Like

That’s what I did, though. (chars)

1 Like

Can you show me that script then? Also you said you replaced every Stage to TeleportedStage

1 Like
local checkpoints = workspace:WaitForChild("Checkpoints")

local coinremote = game.ReplicatedStorage:WaitForChild("CoinGet")

local ms = game:GetService("MarketplaceService")

local vip = 25751808
local mvp = 25751816
local dc = 25751830

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = "0"
	coins.Parent = leaderstats
	
	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Value = "0"
	stage.Parent = leaderstats

	
	
	local prestige = Instance.new("IntValue")
	prestige.Name = "Prestige"
	prestige.Value = "0"
	prestige.Parent = leaderstats
	
	local effectvalue = Instance.new("NumberValue")
	effectvalue.Name = "efftime"
	effectvalue.Parent = player
	
	wait()
	
	local TeleportedStage = Instance.new("IntValue")
	TeleportedStage.Name = "TeleportedStage"
	TeleportedStage.Parent = player
	TeleportedStage.Value = stage.Value
	
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		wait()
		char:MoveTo(checkpoints[stage.Value].Position)

		hum.Touched:Connect(function(hit)
			if hit.Parent == checkpoints then
				if tonumber(hit.Name) == player.TeleportedStage.Value + 1 then
					player.TeleportedStage.Value = player.TeleportedStage.Value + 1
					if not ms:UserOwnsGamePassAsync(player.UserId,vip) and not ms:UserOwnsGamePassAsync(player.UserId,mvp) and not ms:UserOwnsGamePassAsync(player.UserId,dc) then
						coins.Value = coins.Value + 5 -- none
					elseif ms:UserOwnsGamePassAsync(player.UserId,vip) and not ms:UserOwnsGamePassAsync(player.UserId,mvp) and not ms:UserOwnsGamePassAsync(player.UserId,dc) then
						coins.Value = coins.Value + 6 -- vip
					elseif not ms:UserOwnsGamePassAsync(player.UserId,vip) and not ms:UserOwnsGamePassAsync(player.UserId,mvp) and ms:UserOwnsGamePassAsync(player.UserId,dc) then
						coins.Value = coins.Value + 10 -- dc
					elseif not ms:UserOwnsGamePassAsync(player.UserId,vip) and ms:UserOwnsGamePassAsync(player.UserId,mvp) and not ms:UserOwnsGamePassAsync(player.UserId,dc) then
						coins.Value = coins.Value + 7 -- mvp
					elseif ms:UserOwnsGamePassAsync(player.UserId,vip) and ms:UserOwnsGamePassAsync(player.UserId,mvp) and not ms:UserOwnsGamePassAsync(player.UserId,dc) then
						coins.Value = coins.Value + 7 -- vip,mvp
					elseif ms:UserOwnsGamePassAsync(player.UserId,vip) and ms:UserOwnsGamePassAsync(player.UserId,mvp) and ms:UserOwnsGamePassAsync(player.UserId,dc) then
						coins.Value = coins.Value + 10 -- vip,mvp,dc
					elseif not ms:UserOwnsGamePassAsync(player.UserId,vip) and ms:UserOwnsGamePassAsync(player.UserId,mvp) and ms:UserOwnsGamePassAsync(player.UserId,dc) then
						coins.Value = coins.Value + 10 -- mvp,dc
					elseif ms:UserOwnsGamePassAsync(player.UserId,vip) and not ms:UserOwnsGamePassAsync(player.UserId,mvp) and ms:UserOwnsGamePassAsync(player.UserId,dc) then
						coins.Value = coins.Value + 10 -- vip,dc
					end
						
					coinremote:FireAllClients()
				end
			end
		end)
	end)	
end)



1 Like

Replace this with

char:MoveTo(checkpoints[TeleportedStage.Value].Position)

Thats the only thing you should have changed.
Also your script is just as awful as the first script. :slightly_smiling_face:

2 Likes

Thank you SO SO much. I finally can get rid of that two thousand line script and replace it with this after 6 WHOLE, DREADFUL months. Thanks!!!

2 Likes

yeah the checkpoints script? i thought about that but it gets the job done.

1 Like

You are making tens of API calls when player touches checkpoint. You should create BoolValues for every gamepass in every player when they join the game. Then instead of this, you can just check if the player has gamepass like this:

if player.VIP.Value then
   coins.Value += 10
end

Also, to make the script shorter, you can give coins like this:

local gamepasses = {
 ["VIP"] = 5 --How many coins to give?
 ["MVP"] = 10
 ["DC"] = 15
}

for k, v in pairs(gamepasses) do --This will iterate through table. k - gamepass name, v - how many coins it gives
   if player[k].Value then --Means player has gamepass
      coins.Value += v
   end
end

Just make sure that you create values with the same name as the keys in this table.

2 Likes

That searches for the gamepass a player has, but they look for it inside the player.

1 Like

if player[k].Value then checks for value of the BoolValue you’ve created for player when they joined. For example, if k == “VIP” then it will check the value of BoolValue named “VIP” inside the player.
if player[k].Value then is the same as if player:FindFirstChild(k).Value == true then.

I haven’t worked with gamepasses in a while.

What would I set each value to? I forget what the syntax is for checking a player’s gamepass ownership status

local vip = Instance.new("BoolValue")
	
	local mvp = Instance.new("BoolValue")
	
	local dc = Instance.new("BoolValue")

In the same script, where you create TeleportedStage, create 3 BoolValues.

local VIP = Instance.new("BoolValue")
VIP.Name = "VIP"
VIP.Parent = player

local MVP = Instance.new("BoolValue")
MVP.Name = "MVP"
MVP.Parent = player

local DC = Instance.new("BoolValue")
DC.Name = "DC"
DC.Parent = player

local gamepasses = {["VIP"] = 123456, ["MVP"] = 987656, ["DC"] = 019283} --replace with your ID's

for name, ID in pairs(gamepasses) do
   local success, ownsPass = pcall(MarketplaceService.UserOwnsGamePassAsync, MarketplaceService, player.UserId, ID)
   if success and ownsPass then
      player[name].Value = true
   end
end

Edit: changed ipairs to pairs

1 Like

Testing it now, sorry. Applied the edit.

1 Like

It doesn’t work for some reason. All of it, the coins aren’t given, there isn’t any output, and the stage doesn’t change.