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

This leaderboard and text when you die script works in sutdio test but not when I play it normally?

Asked by 8 years ago
Edited 8 years ago

When I use this in studio, it works. When I play the game normally, the leaderboard is not there and it does nothing when I die. Please tell me what I did wrong, thank you.

01Player = game.Players.LocalPlayer
02game.Players.PlayerAdded:connect(function(Player)
03    local stats = Instance.new("IntValue")
04    stats.Parent = Player
05    stats.Name = "leaderstats"
06 
07    local Points = Instance.new("IntValue")
08    Points.Parent = stats
09    Points.Name = "Pointz"
10 
11    deaths = Instance.new("IntValue")
12    deaths.Parent = stats
13    deaths.Name = "Deaths"
14 
15    game.Players.LocalPlayer.CharacterAdded:connect(function() 
View all 32 lines...
0
Is it in a normal script or a local script? IDidMakeThat 1135 — 8y
0
As you are using "LocalPlayer" I assume that this is a local script. You are trying to mix server events with local ones. You need to 1st use a server sctipt for adding the leaderstats nad re-think how the gui side will work. User#5423 17 — 8y
0
This is a normal script, not a local script wierdgamer100 130 — 8y
0
Only local script have acces to localplayer so thats half of the problem.... User#5423 17 — 8y

1 answer

Log in to vote
2
Answered by
systack 123
8 years ago
Edited 8 years ago

Alright, so you've made it clear you're not using a localscript, so here's your problem.

The term (when accessing the "Players" service) "LocalPlayer" refers to the client's player. This can only be used when using a localscript, server scripts do not have a "LocalPlayer". Here's how the script should go.

01game.Players.PlayerAdded:connect(function(Player) --This listens for when a player is added and defines the `argument ` "Player" as the aforementioned player who joined.
02    local stats = Instance.new("IntValue")
03    stats.Parent = Player
04    stats.Name = "leaderstats"
05 
06    local Points = Instance.new("IntValue")
07    Points.Parent = stats
08    Points.Name = "Pointz"
09 
10    deaths = Instance.new("IntValue")
11    deaths.Parent = stats
12    deaths.Name = "Deaths"
13 
14    Player.CharacterAdded:connect(function() 
15       Player.Character.Humanoid.Died:connect(function()
View all 31 lines...

I'm not the best at explaining, but this should fix your issue :)

0
Thank you! wierdgamer100 130 — 8y
0
No problem! You have no idea how long it took me to figure out localplayer didn't work with server scripts when I first began. systack 123 — 8y
0
Yeah, because all of the tutorial books use them in normal scripts :/ wierdgamer100 130 — 8y
Ad

Answer this question