Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempted To Index Nil With Leaderstats Error?

Asked by 4 years ago

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

Log in to vote
1
Answered by
Subsz 366 Moderation Voter
4 years ago

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)

0
Thank you so much! CodedStars 70 — 4y
Ad

Answer this question