Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

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

0

he is using remote events though. -_-

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.