Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempted To Index Nil With Leaderstats Error?

So I'm trying to make it so when you're level (Leaderstats value) equals to 5, it will play a sound, here is the code}

repeat wait() until game.Players.LocalPlayer.Leaderstats.Level.Value == 5 do script.Level000Congrates:Play() wait(1) end

Please Help.

1 answer

✓ Accepted answer

Hey there! I recommend not using a repeat wait() for this because it will just run uselessly. Instead, you can use GetPropertyChangedSignal.

Here's how :

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild('Leaderstats')

leaderstats.Level:GetPropertyChangedSignal('Value'):Connect(function()
if leaderstats.Level.Value == 5 then
script['Level000Congrates']:Play()
end
end)

Make sure this is a local script, and make sure the leaderstats name is 'Leaderstats' (with a capital L)

1 comment

0

Thank you so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.