I have gotten better at scripting but i am still getting errors and this is one of them i do npt understand and cant solve.
I am trying to make a shop gui that upgrades your weapon but it doesn't seem to detect the leaderstats. I cant understand what the error means.
Heres the script
01 | script.Parent.MouseButton 1 Click:Connect( function () |
02 | local human = workspace:FindFirstChild( "Humanoid" ) |
03 | print ( "Humanoid Found!" ) |
04 | local plr = script.Parent.Parent.Parent.Parent |
05 | print ( "Player Found!" ) |
06 | if plr.leaderstats.Points.Value > = 24000 then |
07 | print ( "checked" ) |
08 | plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - 24000 |
09 | script.Parent.Parent.Parent.old:Play() |
10 | wait( 1 ) |
11 | script.Parent.Parent.Parent.olqa:Play() |
12 | wait( 6 ) |
13 | script.Parent.Parent.Parent.olqa:Stop() |
14 | script.Parent.Parent.Parent.buy:Play() |
15 | game.ReplicatedStorage [ "PAP. Ray Gun" ] :Clone().Parent = plr.Backpack |
note: the script is a local script note2: the line thats specifically causing the problems is this
1 | if plr.leaderstats.Points.Value > = 24000 then |
I just need a way to fix this error so that the script can work correctly
it happened because the Leaderstats is not the child of player gui. There should be another Parent
on the plr variable. Here is a helpful video about the Server/Client Relationship and how GUI work on replicated clients.
Here you go the fixed script:
01 | script.Parent.MouseButton 1 Click:Connect( function () |
02 | local human = workspace:FindFirstChild( "Humanoid" ) |
03 | print ( "Humanoid Found!" ) |
04 | local plr = script.Parent.Parent.Parent.Parent.Parent |
05 | print ( "Player Found!" ) |
06 | if plr.leaderstats.Points.Value > = 24000 then |
07 | print ( "checked" ) |
08 | plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - 24000 |
09 | script.Parent.Parent.Parent.old:Play() |
10 | wait( 1 ) |
11 | script.Parent.Parent.Parent.olqa:Play() |
12 | wait( 6 ) |
13 | script.Parent.Parent.Parent.olqa:Stop() |
14 | script.Parent.Parent.Parent.buy:Play() |
15 | game.ReplicatedStorage [ "PAP. Ray Gun" ] :Clone().Parent = plr.Backpack |
Uhh kinda messy script but I cant explain thta well but your doing it wrong and its a bad practice.
heres an example:
01 | local player = game.Players.LocalPlayer |
02 | local character = player.Character or player.CharacterAdded:Wait() |
03 |
04 | local leaderstats = player:WaitForChild( "leaderstats" ) |
05 |
06 | script.Parent.MouseButton 1 Click:Connect( function () |
07 |
08 | if leaderstats.Points.Value > = 24000 then |
09 | -- enough |
10 | print (leaderstats.Points.Value) |
11 | else |
12 | -- not enough |
13 | print (leaderstats.Points.Value - 24000 .. " more points lol" ) |
14 | end |
15 | end ) |
hope I helped :))))))))))))))))))))))))))))))))))))))))))))))))))))))