how do I find out which player ate an item (apple), that is, which player clicked with the left mouse button with that item in their hands. script:
function eatsound () script.Parent.Handle.comendosound:Play() wait(1.4) game.Players.LocalPLayer.--now i don't know what i could put here to find out which player activated the item (apple) and then blow it up script.Parent:Destroy() end script.Parent.Activated:connect(eatsound)
what would i do to find out who was the player who ate the apple and so explode it?
I believe you change this part:
function eatsound()
...to:
function eatsound(plr)
I'm pretty sure that the "plr" (a variable) actually gives the player. Once you do that, you look for the player's character in workspace using plr.Name and you make an exploding script for that.
If that doesn't work, and you're using a local script, you can set up the "plr" variable like this:
local plr = game.Players.LocalPlayer
Hope this helps!
-Maxis_s
well since it's a tool, atleast i assume, then the code must be running in a LoccalScript
.
in a LocalScript
you can do game.Players.LocalPlayer
to get the player where the LoccalScript
is running
so you can do:
local player = game.Players.LocalPlayer local apple = script.Parent function eatsound () print(player.Name, " has eaten an apple") apple.Handle.comendosound:Play() apple:Destroy() end apple.Activated:connect(eatsound);