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

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

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

✓ Accepted answer
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

3 comments

0

Oh, ok! So using playerWhoClicked.Name converted it into a string which allows us to search in the Workspace?

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.

0

Awesome, thanks for your help!

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