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

attempt to index nil with 'FindFirstChild'?

Asked by 2 years ago
game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function()
    game:GetService("Players"):FindFirstChild(script.Parent.Parent.StarterGui.ControlPlayersGUI.CurrencyController.CashGiver.PlayerName.Text):FindFirstChild("leaderstats"):FindFirstChild("Cash").Value = game:GetService("Players"):FindFirstChild(script.Parent.Parent.StarterGui.ControlPlayersGUI.CurrencyController.CashGiver.PlayerName.Text):FindFirstChild("leaderstats"):FindFirstChild("Cash").Value - tonumber(script.Parent.Parent.StarterGui.ControlPlayersGUI.CurrencyController.CashGiver.Amount.Text) -- The error line
end)
0
You are using GetService. Try just using game.Players TheUltimateRealDude1 -9 — 2y
0
It gives me another error, because GetService is a requirement when referring to a player yayaheyman 90 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Server-Sided script: (Fixed!)

-- Cash

script.Parent.GiveCash.OnServerEvent:Connect(function(o, player, amt)
    game.Players[player].leaderstats.Cash.Value = game.Players[player].leaderstats.Cash.Value + amt
end)

script.Parent.RemoveCash.OnServerEvent:Connect(function(o, player, amt)
    game.Players[player].leaderstats.Cash.Value = game.Players[player].leaderstats.Cash.Value - amt
end)

-- Rebirths

script.Parent.GiveRebirths.OnServerEvent:Connect(function(o, player, amt)
    game.Players[player].leaderstats.Rebirths.Value = game.Players[player].leaderstats.Rebirths.Value + amt
end)

script.Parent.RemoveRebirths.OnServerEvent:Connect(function(o, player, amt)
    game.Players[player].leaderstats.Rebirths.Value = game.Players[player].leaderstats.Rebirths.Value - amt
end)

Here is the local script for giving cash: (Fixed!)

script.Parent.MouseButton1Click:Connect(function()
    local player = script.Parent.Parent.PlayerName.Text
    local cash = script.Parent.Parent.Amount.Text
    script.Parent.Parent.Parent.GiveCash:FireServer(player,cash)
end)
0
Try putting a 'wait(1)' above all the code. ZakOMGmcpe564 52 — 2y
0
THANK YOU!!!! yayaheyman 90 — 2y
Ad

Answer this question