So i always get attempt to index nil 'whatever' and im using remote functions, this is when i fire the server
local player = game.Players.LocalPlayer local textbox = script.Parent.Parent.TextBox local button = script.Parent script.Parent.MouseButton1Click:Connect(function(player) game.ReplicatedStorage.CodeRedeem:FireServer(player, textbox, button) end
)
and this script is when the server is fired
game.ReplicatedStorage.CodeRedeem.OnServerEvent:Connect(function(player, textbox, button) local reward = 9000 if textbox.Text == "E" --Insert Codes here then print("Right Code") button.Text = 'Redeemed!' textbox.LocalScript.ching:Play() wait(1) textbox.Text = "[INSERT CODE HERE]" game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + reward else print("Wrong Code") button.Text = "Invalid Code" textbox.LocalScript.error:Play() wait(1) textbox.Text = "[INSERT CODE HERE]" end end)
Hey there. Your issue is that you are either not using enough WaitForChild()
's or you're simply writing your code incorrectly with possible errors in spelling.
WaitForChild's are helpful as they allow the script to wait until it finds the correct child that's needed from a parent.
Furthermore, you don't need to pass "player" to the server as it automatically does it by itself.