Tickets don't get to the player

Hello,
I’m almost finished with my ticket machine, and the problem is that the scrip which should give the tickets, doesn’t work.
Before you get the tickets, you select your choice out of four different tickets, which in total can add up to 9 tickets per purchase. This is defined in ticketChoice, however ticketType is a clone of the original ticket.

ticketType[1] = script.Ticket30Min:Clone()
ticketType[2] = script.Ticket30MinR:Clone()
ticketType[3] = script.OneHour:Clone()
ticketType[4] = script.OneHourR:Clone()

script.Ticket30Min:Destroy()
script.Ticket30MinR:Destroy()
script.OneHour:Destroy()
script.OneHourR:Destroy()

The problem here is that the player doesn’t receive their tickets, error : Workspace.TicketMachineUIGroup.TicketMachineUI.TicketMachine.Screen1.Script:172: attempt to index nil with ‘backpack’

script.Parent.Parent.Parent.Parent.PIN.SurfaceGui.IC.MouseButton1Click:Connect(function(plr)
	for i = 1, #ticketType do
		for j = 1, ticketChoice[i] do
			local t = ticketType[i]:Clone()
			t.Parent = plr.backpack
		end
	end
end)

I haven’t come across a topic where this problem can refer to. (This is a server script) I originally thought something was wrong with the function(plr), but I am really confused at the moment, I’d really appreciate it if someone could help me, thank you for reading!

Its actually Backpack with a capital B
20 charssssssssssssssss

I changed it, and the same error shows up, and I didn’t receive the tickets.

i dont think Mousebutton1clicked returns the player, actually

Player is an argument for MouseClick, but it doesnt exist as a MouseButton1Click argument
You should use the client and fire a remote to the server that they clicked the button

Alright, I will look later into it, and thank you for your fast response!

Is there another way to do it (without remote events)?

You could use ProximityPrompt as it returns the player and just make it a click with a one second timer

And I would really consider using a remote event and just using security for faster input time.

The problem is that I don’t know how remote events work, but more important, this ticket machine will be inside a tram, and the tram get’s spawned in with a script, (I could be wrong) but how would I duplicate the script in startercharacterscript.

The client script would look like this :

local remote = nil; --Change this to a remote
local clicked = nil; --What you are clicking

clicked.MouseButton1Click:connect(function()
	remote:FireServer("TicketRequest"); --Sends a message to the server
end);

And the server script would look like this :

local remote = nil; --Change this to a remote
remote.OnServerEvent:connect(function(x,r) --x is the player who sent it
	if r == "TicketRequest" then --r is the argument
		--do your ticket giving here
	end;
end);

Remotes are very useful, you will be forced to use them in a lot of situations

This guide can help you know what they do