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

How do i find myself in Players with a script and not a local script?

Asked by 5 years ago

I'm trying to give myself stats for a game and it keeps giving me errors.

script.Parent.Parent.Players.LocalPlayer.PlayerGui.Interface.ButtonSideInterface.Rebirth.TextButton.MouseButton1Click:Connect(function()
    print("Rebirthing")
    if game.Players.LocalPlayer.leaderstats.Money == 100000 * game.Players.LocalPlayer.leaderstats.Rebirths then
        game.Players.LocalPlayer.leaderstats.Money = 0
        game.Players.LocalPlayer.leaderstats.Rebirths = game.Players.LocalPlayer.leaderstats.Rebirths.Value + 1
    else
        script.Parent.Parent.Players.LocalPlayer.PlayerGui.Interface.MessageBox.Frame.Message.Text = "You do not have enough money to purchase this item!"
        script.Parent.Parent.Players.LocalPlayer.PlayerGui.Interface.MessageBox.Frame.Top.Text = "Oops!"
        script.Parent.Parent.Players.LocalPlayer.PlayerGui.Interface.MessageBox.MessageBox.Button.Text = "Ok."

        print("Rebirth failed due to invalid stats.")
    end
end)

3 answers

Log in to vote
1
Answered by
Creacoz 210 Moderation Voter
5 years ago
Edited 5 years ago

Instead of rebirths it would be rebirths.Value on line 3 Also you forgot most of the .Value Make a RemoteEvent in replicated storage and name it "rebirth"

Put this in the local button:

script.Parent.MouseButton1Click:Connect(function()
    game:GetService("ReplicatedStorage").rebirth:FireServer()
end)

And put that in a server script

game:GetService("ReplicatedStorage").rebirth.OnServerEvent:Connect(function(plr)
    print("Rebirthing")
    if plr.leaderstats.Money.Value == 100000 * plr.leaderstats.Rebirths.Value then
       plr.leaderstats.Money.Value = 0
        plr.leaderstats.Rebirths.Value  = plr.leaderstats.Rebirths.Value + 1
    else
        plr.PlayerGui.Interface.MessageBox.Frame.Message.Text = "You do not have enough money to purchase this item!"
        plr.PlayerGui.Interface.MessageBox.Frame.Top.Text = "Oops!"
        plr.PlayerGui.Interface.MessageBox.Frame.Button.Text = "Ok."

        print("Rebirth failed due to invalid stats.")
    end
end)
0
ServerScriptService.Script:1: attempt to index field 'LocalPlayer' (a nil value) iiDkOffical 109 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You have to type .Value to add to something. Let me show you:

Script running server sided

game.Players.PlayerAdded:Connect(function(p)
    if p.leaderstats.Money.Value == 100000 * p.leaderstats.Rebirths.Value then
        p.leaderstats.Money.Value = 0
        p.leaderstats.Rebirths = p.leaderstats.Rebirths.Value +1
    else
        p:WaitForChild("PlayerGui").Interface.MessageBox.Frame.Message.Text = "You do not have enough money to purchase this item!"
        p:WaitForChild("PlayerGui").Interface.MessageBox.Frame.Top.Text = "Oops!"
        p:WaitForChild("PlayerGui").Interface.MessageBox.MessageBox.Button.Text = "Ok."

        print("Rebirth failed due to invalid stats.")
    end
end)
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local player = script.Parent.Parent

player.PlayerGui.Interface.ButtonSideInterface.Rebirth.TextButton.MouseButton1Click:Connect(function()
    print("Rebirthing")
    if player.leaderstats.Money == 100000 * player.leaderstats.Rebirths then
        player.leaderstats.Money = 0
        player.leaderstats.Rebirths = player.leaderstats.Rebirths.Value + 1
    else
        player.PlayerGui.Interface.MessageBox.Frame.Message.Text = "You do not have enough money to purchase this item!"
        player.PlayerGui.Interface.MessageBox.Frame.Top.Text = "Oops!"
        player.PlayerGui.Interface.MessageBox.MessageBox.Button.Text = "Ok."

        print("Rebirth failed due to invalid stats.")
    end
end)
0
here is the solution YahiaElramal_77 26 — 5y
0
didnt work iiDkOffical 109 — 5y

Answer this question