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

How to find a player from a function?

Hello, fellow Lua users. I am quite new to Roblox scripting and I would want to ask you how can you find a player that clicked an object. For example, I tried this method: ...MouseButton1Down:connect(function(plr) plr = game.Players:FindFirstChild(plr). This did not really work out. Here is the full script if you want to look at it

script.Parent.ClickDetector.MouseClick:connect(function(c)
	local plr = game.Players:FindFirstChild(c)
	if plr.PlayerGui.CarName.Value == "power" then
		script.Parent.Material = "SmoothPlastic"
	local clone = game.ServerStorage["2011 F-250 Super Duty 6.7L Power Stroke"]:Clone()
	clone.Parent = game.Workspace
	end
end)

I hope this question was understandable enough with my lack of English.

2 answers

✓ Accepted answer

As luke said, 'c' would be the player. So FindFirstChild() to get the player is useless, as the player is 'c'. I would say the error is with 'local plr = game.Players:FindFirstChild(c)' The argument for FindFirstChild() is a string, and you are feeding it an object. Other than that, seems fine.

2 comments

0

So can I just say 'if c.PlayerGui.CarName.Value == "power"?

0

Yes.

Using FindFirstChild is completely useless as MouseClick returns the player object located under game.Players

3 comments

0

But what would you do to find a player object if FindFirsrChild is completely useless?

0

Read the answer: MouseClick returns it

0

It's also worth noting that the server can't see things in PlayerGui the server didn't directly create if FE is toggled true.

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