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

How do I use the "playerWhoClicked" parameter to find the player in the Workspace?

Asked by 4 years ago

So basically I'm trying to make a button that makes the player who clicks it explode. When I tried using the "playerWhoClicked" parameter it returned the correct username. But when I try to use the username to find the player in the Workspace it doesn't work properly. An example of the code I'm using is at the bottom, I haven't put in the explosive stuff yet because I haven't gotten it to work.

local clicker = script.Parent.ClickDetector

function clickDetect(playerWhoClicked)
    local duckie = playerWhoClicked
    print(duckie)
    if game.Workspace:FindFirstChild(duckie) then
        print(":)") else
        print(":(")
    end
end

clicker.MouseClick:Connect(clickDetect)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
local clicker = script.Parent.ClickDetector

function clickDetect(playerWhoClicked)
    local duckie = playerWhoClicked.Name
    print(duckie)
    if game.Workspace:FindFirstChild(duckie) then
        print(":)") else
        print(":(")
    end
end

clicker.MouseClick:Connect(clickDetect)

The problem was playerWhoClicked refers to an object. print() commands refer to a string in it's attribute, not an object.
Regards, Vivilian9

0
Oh, ok! So using playerWhoClicked.Name converted it into a string which allows us to search in the Workspace? Beastlance 22 — 4y
0
Yeah, Exactly! With playerWhoClicked being an object in a print command's attribute, that made an error and the script came to a stop. ViviTheLuaKing 103 — 4y
0
Awesome, thanks for your help! Beastlance 22 — 4y
Ad

Answer this question