Problem With Leveling System

I have created a leveling system, I have created a value called EXP which is updated by climbing on a platform,

I would like that if the player has more than 100 EXP touching a part it turns yellow, It doesn’t work …

What Did I Do Wrong?!

SCRIPT:
local EXP = player.Stats.EXP.Value

local PT = script.Parent

local player = game:GetService(“Players”)

wait(1)

if player.Stats.EXP.Value >= 0 then
PT.BrickColor = BrickColor.new(“Brick yellow”)
end


is this under a .touched event?

No, But adding it doesn’t work either, I wish the script would also work with a “print (” “)”

can you show code of how you tried to do the .touched

If it’s not inside a function you need to mention what player is.

and how do i fix it? :sweat_smile:

Hmm,…

local player = game:GetService(“Players”)
I think you need to move this line at the top

yeah here!

local EXP = player.Stats.EXP.Value

local PT = script.Parent

local player = game:GetService(“Players”)

wait(1)

PT.Touched:Connect(function(hit)
if player.Stats.EXP.Value >= 0 then
PT.BrickColor = BrickColor.new(“Brick yellow”)
end

It does not work,
Can You Send Me A Script For This?

I have a question.

player:GetService(“Players”)
Does this mean Stats is inside of game.Players?

You should be getting the player from the .touched event. Not outside it.

If you did manage to get this to work but put the EXP variable outside then it would get only the number the EXP was when this was created. Let’s say the player starts off with 100. Every time they would touch it would just show 100 because you aren’t getting their new EXP value.
player isn’t defined anywhere so it should’ve already errored in output.
It’s also useless because you never actually used it in the script.

Here you’re just getting the service with all the players inside and not the player you want to change.

Here’s a working script.

local PT = script.Parent--The part
local playerService = game:GetService("Players")-- Player service with all the players


PT.Touched:Connect(function(hit)--Touch function
	if hit.Parent:FindFirstChild("Humanoid") then--Check if a character touches it using the hit
		if playerService:GetPlayerFromCharacter(hit.Parent) then -- Check if it's a player
			local Player = playerService:GetPlayerFromCharacter(hit.Parent) -- Get the player
			local EXP = Player.Stats.EXP--The stats value object 

			if EXP.Value >= 100 then
				PT.BrickColor = BrickColor.new("Brick yellow")
			end
		end
	end
end)

Please use this to learn and don’t just copy the script and move on with your day because you wouldn’t have learned absolutely nothing.

1 Like

Its a folder under the player, with values.

Thank you so much!
I’m Learning In The World Of Scripting, This Will Help Me!