So basically i’m trying to make a exp. and level system I want want it so that when you touch this certain part, you exp from it.
I’ve added print statements and testing it, but like the whole script just fails. I also asked someone to help me see if there were any problems. (two pairs of eyes are better than one )
I would really appreciate it if someone could help me with this. Thanks for reading :
game.Players.PlayerAdded:Connect(function(plr)
local a = Instance.new(“Folder”,plr)
a.Name = “leaderstats”
local x = Instance.new(“IntValue”,a)
x.Value = 0
x.Name = “exp”
end)
while true do
end
local BlckLndsEndZne = game.Lighting.Map1.BlockLandsEndZone
print(“done line 1”)
workspace.BlckLndsEndZne.Touched:connect(function(hit)
print(“done line 15”)
if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
print(“done line 17”)
local exp = game.ServerScriptService.experiencepoints
print(“done line 19”)
exp = exp +25
print(“done line 21”)
exp.Position = hit.Position
print(“done line 23”)
exp.Parent = workspace
print(“done line 25”)
end
end)
local exp = game.StarterGui.ExpAndLvl.ExpPoints
local lvl = game.StarterGui.ExpAndLvl.PlrLevel
local win = game.ServerScriptService.LevelLeaderBoard
if exp.Value == 25 then
lvl = lvl +1
print(“You reached level 1!”)
end
This is going to cause a game script timeout. It’s probably why the whole script just fails. It’s empty anyway, so you should just remove that section.
local Players = game:GetService("Players")
local function newLeaderStatsFolder(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name ="leaderstats"
leaderstats.Parent = player
local experience = Instance.new("IntValue")
experience.Name = "Experience"
experience.Value = 0 --If you have a datastore then this would be where to connect the DataStore value
experience.Parent = leaderstats
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 0 --DataStore save would go here
level.Parent = leaderstats
end
local function determineLevelUp(player)
if Players.player.leaderstats.Experience = 100 then
Players.player.leaderstats.Level = Players.player.leaderstats.Level + 1
Players.player.leaderstats.Experience = 0
end
end
local function addExperienceToPlayer(hit)
local debouce = false
if hit.Parent:FindFirstChild("Humanoid") then
if Players:GetPlayerFromCharacter(hit) then
if not debounce then
debounce = true
Players.hit.leaderstats.Value = Players.hit.leaderstats.Experience.Value + 25
determineLevelUp(Players:GetPlayerFromCharacter(hit))
wait(10)
debounce = false
end
end
end
end
Players.PlayerAdded:Connect(newLeaderStatsFolder)
game.Workspace.BlckLndsEndZne.Touched:Connect(addExperienceToPlayer)
Don’t use the second argument for Instance.new(), there was a thread in 2016
that addressed this.
Second,
what is the purpose of this empty while loop??
Try to use descriptive variables so that it is easy to catch errors, instead of defining a folder as x, define it as leaderstats = etc.
Do not attempt to use Lighting for storing instances, this usage is legacy like and use either ReplicatedStorage or ServerStorage to store items instead .
This code is outside the function bound to the PlayerAdded event, it would error if workspace.BlckLndsEndZne did not exist.
Make sure this is a script then, local scripts can’t access ServerScriptService as it’s contents are not replicated.
Also you are attempting to add an instance to 25, you meant to do something like this instead:
local exp = something.Points
exp.Value = exp.Value + 25
Now I am not sure what exp is at all if it has a supposed Position property.
What? game.StarterGui’s contents are replicated into a player’s PlayerGui, access that by doing
local PlayerGui = player:WaitForChild("PlayerGui", 5)
-- returns nil if the instance wasn't found within 5 seconds
Implement some sort of debounce mechanism.
Use :Connect (capital C), connect is deprecated.
I don’t think any print statement at all will print.
Please, format code; it’ll be better for us (and you) to debug.