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.
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!
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
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.
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