The "player" argument doesn't work

local BindableFunction = game:GetService("ReplicatedStorage").Function

script.Parent.MouseButton1Click:Connect(function(player)
	local Result = BindableFunction:Invoke(player)
	local nd = player.CharacterAppearanceId
	local nh = game.Workspace.PlayersInfo[tostring(nd)]:GetAttribute("HaveTicket")
	script.Parent.Parent.Parent.Enabled = false
	if nh == false and Result == "yes" then
		game.Workspace.PlayersInfo[tostring(nd)]:SetAttribute("HaveTicket", true)
		print("Player "..player.Name, player.CharacterAppearanceId.." buy ticket to city")
		script.Parent.Parent.Parent.Parent.TicketBuy.Enabled = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.TicketBuy.Enabled = false
		script.Parent.Parent.Parent.Parent.vibor.Enabled = true
	elseif nh == false and Result == "no" then
		print("Player "..player.Name, player.CharacterAppearanceId.." haven't money for buy ticket to city")
		script.Parent.Parent.Parent.Parent.HaventMoney.Enabled = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.HaventMoney.Enabled = false
		script.Parent.Parent.Parent.Parent.vibor.Enabled = true
	elseif nh == true then
		print("Player "..player.Name, player.CharacterAppearanceId.." already have ticket to city")
		script.Parent.Parent.Parent.Parent.HaveTicket.Enabled = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.HaveTicket.Enabled = false
		script.Parent.Parent.Parent.Parent.vibor.Enabled = true
	else
		print("Error buy ticket"..player.Name, player.CharacterAppearanceId)
		script.Parent.Parent.Parent.Parent.Error.Enabled = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.Error.Enabled = false
		script.Parent.Parent.Parent.Parent.vibor.Enabled = true
	end
end)

Basically, you don’t need a script here, but I decided to add it just in case.

I have a script, and I specified player in the arguments of its function. However, when I run this script, the parts of the code that come after player don’t work (for example, player.Name or player.CharacterAppearanceId).

In another script, everything worked for me according to the same principle. I tried to get a response from the artificial intelligence built into Roblox Studio, but it told me that the problem is due to the fact that I activate the function via MouseButton1Click. It seems to me that this is some kind of nonsense, if you know how to fix it, please help.

I apologize if it is written in a strange way or I don’t use the translator correctly because I don’t know English.

2 Likes

Assuming that this is running on the Client, you should do another variable:

local player = game.Players.LocalPlayer

MouseButton1Click does not give the player that clicked it

3 Likes
local BindableFunction = game:GetService("ReplicatedStorage").Function
local player = game.Players.LocalPlayer


script.Parent.MouseButton1Click:Connect(function()
	local Result = BindableFunction:Invoke(player)
	local nd = player.CharacterAppearanceId
	local nh = game.Workspace.PlayersInfo[tostring(nd)]:GetAttribute("HaveTicket")
	script.Parent.Parent.Parent.Enabled = false
	if nh == false and Result == "yes" then
		game.Workspace.PlayersInfo[tostring(nd)]:SetAttribute("HaveTicket", true)
		print("Player "..player.Name, player.CharacterAppearanceId.." buy ticket to city")
		script.Parent.Parent.Parent.Parent.TicketBuy.Enabled = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.TicketBuy.Enabled = false
		script.Parent.Parent.Parent.Parent.vibor.Enabled = true
	elseif nh == false and Result == "no" then
		print("Player "..player.Name, player.CharacterAppearanceId.." haven't money for buy ticket to city")
		script.Parent.Parent.Parent.Parent.HaventMoney.Enabled = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.HaventMoney.Enabled = false
		script.Parent.Parent.Parent.Parent.vibor.Enabled = true
	elseif nh == true then
		print("Player "..player.Name, player.CharacterAppearanceId.." already have ticket to city")
		script.Parent.Parent.Parent.Parent.HaveTicket.Enabled = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.HaveTicket.Enabled = false
		script.Parent.Parent.Parent.Parent.vibor.Enabled = true
	else
		print("Error buy ticket"..player.Name, player.CharacterAppearanceId)
		script.Parent.Parent.Parent.Parent.Error.Enabled = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.Error.Enabled = false
		script.Parent.Parent.Parent.Parent.vibor.Enabled = true
	end
end)
2 Likes

.MouseButton1Click does not have a “player” argument, so do what the post above me said and add a player variable if it is in a Localscript

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.