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!!!
yeah the checkpoints script? i thought about that but it gets the job done.
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.
That searches for the gamepass a player has, but they look for it inside the player.
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
Testing it now, sorry. Applied the edit.
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.
Can you show the script? (chars)
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 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"] = 25751808, ["MVP"] = 25751816, ["DC"] = 25751830}
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
wait()
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(checkpoints[TeleportedStage.Value].Position)
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints then
for name, ID in pairs(gamepasses) do
local success, ownsPass = pcall(ms.UserOwnsGamePassAsync, ms, player.UserId, ID)
if success and ownsPass then
player[name].Value = true
end
end
There are âendsâ and '(ends) at the bottom I just didnât include them.
Replace code at the bottom of the script with the code that I gave you before.
local gamepassToCoins = {
["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
The stage doesnt change because you dont change the value of it.
Also set the name of second table to gamepassToCoins so there will be no variables with the same names.
So I tried replacing the text, nothing worked, and then added the text, which at least got the leaderstats working but didnât work when i tried to get the checkpoint.
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 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 gamepassToCoins = {["VIP"] = 25751808, ["MVP"] = 25751816, ["DC"] = 25751830}
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
wait()
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(checkpoints[TeleportedStage.Value].Position)
hum.Touched:Connect(function(hit)
local gamepasses = {
["VIP"] = 5, --How many coins to give?
["MVP"] = 7,
["DC"] = 10,
}
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
if hit.Parent == checkpoints then
for name, ID in pairs(gamepasses) do
local success, ownsPass = pcall(ms.UserOwnsGamePassAsync, ms, player.UserId, ID)
if success and ownsPass then
player[name].Value = true
end
end
--[[
if tonumber(hit.Name) == player.leaderstats.Stage.Value + 1 then
player.leaderstats.Stage.Value = player.leaderstats.Stage.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)
No, no, no.
Iâll better do it for you.
local checkpoints = workspace:WaitForChild("Checkpoints")
local coinremote = game.ReplicatedStorage:WaitForChild("CoinGet")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamepassToCoins = {
["VIP"] = 5,
["MVP"] = 7,
["DC"] = 10,
}
local gamepasses = {["VIP"] = 25751808, ["MVP"] = 25751816, ["DC"] = 25751830}
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 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
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
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
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")
char:MoveTo(checkpoints[TeleportedStage.Value].Position)
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints and tonumber(hit.Name) == stage.Value + 1 then
for k, v in pairs(gamepassToCoins) do
if player[k].Value then
coins.Value += v
end
end
stage.Value = hit.Name
end
end)
end)
end)
This doesnt include stage updating.
Edit: now it does
One, when I join, my stage value is 0 but the top says my actual stage.
Two, when I touch a checkpoint, I get a random amount of coins. I get a lot of coins.
Also, when I respawn, I respawn at stage 0.
What is the top?
Its not actually random. You can set how many coins each gamepass gives. If I understand correctly, you want to give player coints for each checkpoint they touch?
Did you mean leaderboard by the top?