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.

Player = game.Players.LocalPlayer
game.Players.PlayerAdded:connect(function(Player)
    local stats = Instance.new("IntValue")
    stats.Parent = Player
    stats.Name = "leaderstats"

    local Points = Instance.new("IntValue")
    Points.Parent = stats
    Points.Name = "Pointz"

    deaths = Instance.new("IntValue")
    deaths.Parent = stats
    deaths.Name = "Deaths"

    game.Players.LocalPlayer.CharacterAdded:connect(function()  
        game.Players.LocalPlayer.Character.Humanoid.Died:connect(function()
            deaths.Value = deaths.Value + 1
            local deathGui = Instance.new("ScreenGui")
            deathGui.Parent = game:GetService("Players").LocalPlayer.PlayerGui

            local deathText = Instance.new("TextBox")
            deathText.Parent = deathGui
            deathText.Text = "YOU SUCK, "..game.Players.LocalPlayer.Name
            deathText.FontSize = "Size96"
            deathText.Position = UDim2.new(0.5,0,0.5,0)
            deathText.BackgroundTransparency = 1
            deathText.TextColor3 = Color3.new(255,255,255)
            wait(5)
            deathGui:Remove()
        end)
    end)
end)
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.

game.Players.PlayerAdded:connect(function(Player) --This listens for when a player is added and defines the `argument ` "Player" as the aforementioned player who joined.
    local stats = Instance.new("IntValue")
    stats.Parent = Player
    stats.Name = "leaderstats"

    local Points = Instance.new("IntValue")
    Points.Parent = stats
    Points.Name = "Pointz"

    deaths = Instance.new("IntValue")
    deaths.Parent = stats
    deaths.Name = "Deaths"

    Player.CharacterAdded:connect(function()  
       Player.Character.Humanoid.Died:connect(function()
            deaths.Value = deaths.Value + 1
            local deathGui = Instance.new("ScreenGui")
            deathGui.Parent = Player.PlayerGui

            local deathText = Instance.new("TextBox")
            deathText.Parent = deathGui
            deathText.Text = "YOU SUCK, "..Player.Name:upper()
            deathText.FontSize = "Size96"
            deathText.Position = UDim2.new(0.5,0,0.5,0)
            deathText.BackgroundTransparency = 1
            deathText.TextColor3 = Color3.new(255,255,255)
            wait(5)
            deathGui:Destroy() --don't use deprecated methods ; )
        end)
    end)
end)

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