You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to get the player’s current leaderstats Level value in runtime when the player touches a part, then let them enter if they have Level x or higher on their stats. -
What is the issue? Include screenshots / videos if possible!
The script works fine until you change the value in the runtime. The script doesn’t detect the value change in runtime, but it does if you change it then start the game, which makes the code think that you still have, lets say, level 1, when your current leaderstats say level 2. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I didn’t find any questions related to this, so I wrote this post.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
This is the leaderstats code (in ServerScriptService):
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "leaderstats"
print(3)
local level = Instance.new("IntValue", leaderstats)
level.Name = "Level"
level.Value = 1
end)
Part.Touched script (Script that is on the part):
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:FindFirstChild(hit.Parent.Name)
if plr:FindFirstChild("leaderstats").Level.Value == 2 then
script.Parent.CanCollide = false
wait(3)
script.Parent.CanCollide = true
else
end
end
end)