Can i put this function in a function?

i just want to know if i can putt this function giveTag in this other function calld seatPlrs. it doesnt seem to work idk why tho

function seatPlrs(plr:Player)
	
	local function giveTag(plr:Player) -- can i put this here?
		local owner = game.ReplicatedStorage.owner2
		local oc = owner:Clone()
		local hum:Humanoid = plr.Character:WaitForChild("Humanoid")
		oc.Parent = plr.Character.Head
		oc.TextLabel.Text = "Works"
	end
	
	giveTag(plr)
	
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum:Humanoid = char:FindFirstChildOfClass("Humanoid")
	local hrp = char:WaitForChild("HumanoidRootPart")

	hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

if hum then

for i, seat in pairs(seatStatus) do
			if seat.taken == false then
seat.chair:Sit(hum)
seat.taken = true

--if seat.chair.Occupant then
--				hum.JumpHeight = 0
--				hum.JumpPower = 0
--				end

break

			else
			end	
			end
end
end

game.Players.PlayerAdded:Connect(seatPlrs)

You can, but I’m not sure why you would want to. Why not just put the “giveTag” function outside of your “seatPlrs” function?

Edit: Also, your issue comes from you not passing in the player to the “seatPlrs” function. Replace this part:

With this:

game.Players.PlayerAdded:Connect(function(plr)
	seatPlrs(plr)
end)
1 Like

Those do the same thing:

local function foo(...)
   print(...) -- prints "Name" twice
end

script.Changed:Connect(foo)
script.Changed:Connect(function(...)
   foo(...)
end)

script.Name = "example"
1 Like

@9100ryan @HugeCoolboy2007

hey guys, tysm 4 ur replies. both answers are fantastic. i was just experimenting with the code to get a better understanding. thank u both so much 4 the solutions! :smiley:

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