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

Im trying to make a code script that fires to the server, but i cant get it to work?

Asked by 4 years ago

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)
1
lol why use remote function, if u want to fireserver try using remote event, heres for more info lol https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events Friskyman321 121 — 4y
0
he is using remote events though. -_- User#29913 36 — 4y

1 answer

Log in to vote
0
Answered by
o_fex 146
4 years ago

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.

Ad

Answer this question