Hi! I’m Dylan
Recently I have been working on a project, and it involves leveling up, but I’m not good at scripting, so I kinda need some help with it.
Here’s how it would work:
So basically, every 5 minutes you would level up, and every level you earn, you unlock a new area
(So a part Would turn CanCollide off when the player reaches a certain level)
Also if a player rejoins or resets, The levels that that player have gotten to are still there, and the part still has CanCollide turned off.
I don’t really mind if anybody can walk through the part when CanCollide is turned off, as the game that i’m making is only going to have a 1 player server
Thank you!
-DylanPickle
You need to use leaderstats and datastores to get the player’s level. Inside a server script, you can set this up and every 5 minutes add a level to the user.
Then, in a local script, you can use an .onChanged:connect() to detect if the player’s level is changed and then update the area’s doors off of that.
what would i put in the script though? I’m not that good at scripting
the only way to learn is to do it yourself. Googling “level up system in roblox” gives you some good resources for leaderstats and datastores.
I found stuff on how to make it so you get it using coins, but not levels
try that:
server:
local datastore = game:GetService("DataStoreService"):GetDataStore("_GameExperience")
local SaveTable = {}
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player) -- create a leaderstats folder and parent to player
leaderstats.Name = "leaderstats"
local Level = Instance.new("IntValue",leaderstats) -- create the leaderstats level and parent to leaderstats
Level.Name = "Level"
local data
local sucess,err = pcall(function()
data = datastore:GetAsync(player.UserId)
end)
SaveTable["Currency"] = nil
if data then -- if a data exist in the player key
Level.Value = data["Currency"]
end
coroutine.wrap(function()
while wait(5*60) do -- Every 5 minutes gives 1 level
player.leaderstats.Level.Value += 1
end
end)()
game.Players.PlayerRemoving:Connect(function(player)
if player then
SaveTable["Currency"] = player.leaderstats.Level.Value
datastore:SetAsync(player.UserId,SaveTable) -- Sets the current level value to key.
end
end)
Client(localscript):
local player = game.Players.LocalPlayer -- gets the client player
local Level = player.leaderstats:WaitForChild("Level") -- gets the level value
local UnlockLevel = ur unlock level
local door = ur path to door
Connection = Level.Changed:Connect(function(newlevel)
if newlevel >= UnlockLevel then -- check if player newlevel = UnlockLeveç
if door.CanCollide then -- Check if the door was not already Open
door.CanCollide = false
else
Connection:Disconnect()
end
else
print("Levels to Unlock Door:"..(UnlockLevel-newlevel))
end
end)
how would i make a parent to player or leaderstats?
wdym? the script or something else?
for the first script it says “create a leaderstats folder and parent to player”
and also "create the leaderstats level and parent to leaderstats
What would i do there?
and in the second script it says “ur path to door” what does that mean, what do i replace it with?
sorry if i dont make much sense, im pretty new to scripting
ah lol oops my bad
i mean the script already parented to player or to leaderstats and the “ur path to door” means where is ur area door.
so would i put like, the coordinates of the door?
no where is it in workspace like if u put this script below the area door put “script.Parent”
it just makes the door disappear
the door is anchored right???
yup. I anchored it, then put it inside the script in ServerScriptService
and the client(local script) u put,where?
I put the localscript in NetworkClient
change that for below the area door.
Put the local script in starterplayerscripts
NetworkClient is only responsible for connecting a client to a server i think.
1 Like