Getting the player

Hey there,

I have this peice of code:

function openChest()
	
	
	print("Clicked on handle.")
	
	if not debounce then
		debounce = true
		if Chest.Open.Value then
			rotate(Lid, increment)
		else
			rotate(Lid, -increment)
		end
		Chest.Open.Value = not Chest.Open.Value
		debounce = false
	else
	end
end

Lid.ClickDetector.MouseClick:Connect(openChest)

The code works fine, but I want to take the player who clicked on it and change some of its stats when this happened. How would I get the player in this script?

Thank you for helping. If you need any more information, just let me know.

Hey, I don’t like usually giving code but this is a simple fix! I added a player parameter in the openChest function.

function openChest(player)
	
	
	print("Clicked on handle.")
	
	if not debounce then
		debounce = true
		if Chest.Open.Value then
			rotate(Lid, increment)
		else
			rotate(Lid, -increment)
		end
		Chest.Open.Value = not Chest.Open.Value
		debounce = false
	else
	end
end

Lid.ClickDetector.MouseClick:Connect(openChest)
1 Like