Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to find a player from a function?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

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.

0
So can I just say 'if c.PlayerGui.CarName.Value == "power"? TimTimich6 6 — 6y
0
Yes. H4X0MSYT 536 — 6y
Ad
Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
6 years ago

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

0
But what would you do to find a player object if FindFirsrChild is completely useless? TimTimich6 6 — 6y
0
Read the answer: MouseClick returns it lukeb50 631 — 6y
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. CootKitty 311 — 6y

Answer this question