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

how do I find out which player activated the function?

Asked by
lytew 99
4 years ago

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?

2 answers

Log in to vote
0
Answered by
Maxis_s 97
4 years ago

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

0
nice WyattagumsBackUp 5 — 4y
0
you will try here, but what is the function of 'localplayer'? lytew 99 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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);

Answer this question