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.

01script.Parent.Parent.Players.LocalPlayer.PlayerGui.Interface.ButtonSideInterface.Rebirth.TextButton.MouseButton1Click:Connect(function()
02    print("Rebirthing")
03    if game.Players.LocalPlayer.leaderstats.Money == 100000 * game.Players.LocalPlayer.leaderstats.Rebirths then
04        game.Players.LocalPlayer.leaderstats.Money = 0
05        game.Players.LocalPlayer.leaderstats.Rebirths = game.Players.LocalPlayer.leaderstats.Rebirths.Value + 1
06    else
07        script.Parent.Parent.Players.LocalPlayer.PlayerGui.Interface.MessageBox.Frame.Message.Text = "You do not have enough money to purchase this item!"
08        script.Parent.Parent.Players.LocalPlayer.PlayerGui.Interface.MessageBox.Frame.Top.Text = "Oops!"
09        script.Parent.Parent.Players.LocalPlayer.PlayerGui.Interface.MessageBox.MessageBox.Button.Text = "Ok."
10 
11        print("Rebirth failed due to invalid stats.")
12    end
13end)

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:

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

And put that in a server script

01game:GetService("ReplicatedStorage").rebirth.OnServerEvent:Connect(function(plr)
02    print("Rebirthing")
03    if plr.leaderstats.Money.Value == 100000 * plr.leaderstats.Rebirths.Value then
04       plr.leaderstats.Money.Value = 0
05        plr.leaderstats.Rebirths.Value  = plr.leaderstats.Rebirths.Value + 1
06    else
07        plr.PlayerGui.Interface.MessageBox.Frame.Message.Text = "You do not have enough money to purchase this item!"
08        plr.PlayerGui.Interface.MessageBox.Frame.Top.Text = "Oops!"
09        plr.PlayerGui.Interface.MessageBox.Frame.Button.Text = "Ok."
10 
11        print("Rebirth failed due to invalid stats.")
12    end
13end)
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

01game.Players.PlayerAdded:Connect(function(p)
02    if p.leaderstats.Money.Value == 100000 * p.leaderstats.Rebirths.Value then
03        p.leaderstats.Money.Value = 0
04        p.leaderstats.Rebirths = p.leaderstats.Rebirths.Value +1
05    else
06        p:WaitForChild("PlayerGui").Interface.MessageBox.Frame.Message.Text = "You do not have enough money to purchase this item!"
07        p:WaitForChild("PlayerGui").Interface.MessageBox.Frame.Top.Text = "Oops!"
08        p:WaitForChild("PlayerGui").Interface.MessageBox.MessageBox.Button.Text = "Ok."
09 
10        print("Rebirth failed due to invalid stats.")
11    end
12end)
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01local player = script.Parent.Parent
02 
03player.PlayerGui.Interface.ButtonSideInterface.Rebirth.TextButton.MouseButton1Click:Connect(function()
04    print("Rebirthing")
05    if player.leaderstats.Money == 100000 * player.leaderstats.Rebirths then
06        player.leaderstats.Money = 0
07        player.leaderstats.Rebirths = player.leaderstats.Rebirths.Value + 1
08    else
09        player.PlayerGui.Interface.MessageBox.Frame.Message.Text = "You do not have enough money to purchase this item!"
10        player.PlayerGui.Interface.MessageBox.Frame.Top.Text = "Oops!"
11        player.PlayerGui.Interface.MessageBox.MessageBox.Button.Text = "Ok."
12 
13        print("Rebirth failed due to invalid stats.")
14    end
15end)
0
here is the solution YahiaElramal_77 26 — 5y
0
didnt work iiDkOffical 109 — 5y

Answer this question