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

How can I reference the local player in a standard script?

Asked by
J_98482 18
5 years ago

Quick question - I have a standard script in my workspace that fires when a user clicks on a block. The script that fires when the block is clicked needs to point to an object within the the player's player-folder, so I'm looking for an alternative to LocalPlayer that doesn't need to be ran inside of a LocalScript in order to work properly. Any suggestions? Thanks in advance.

0
Please show your current code so we can further assist you. popeeyy 493 — 5y

2 answers

Log in to vote
0
Answered by
Astralyst 389 Moderation Voter
5 years ago

Considering that you're using the script to get the person who clicked the brick's name,

.MouseClick should do the trick. https://www.robloxdev.com/api-reference/event/ClickDetector/MouseClick

script.Parent.ClickDetector.MouseClick:connect(function(player)
print(player)
end)

the output should be the person who clicked on the button's name ^ based on the example, you probably would already know what'd you need to do after that.

if you're trying to find the player's character, then just do

workspace:FindFirstChild(player)

if you're trying to find the player's player, just do

game.Players:FindFirstChild(player)

et cetera, the rest are self explanatory.

0
this should do the trick for events that already has a "playerWhoClicked" by default anyways, other than that, you can always use remoteevents. Astralyst 389 — 5y
0
you can just use player.Character User#23365 30 — 5y
0
well, i guess that works aswell /shrug Astralyst 389 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

First: make a remote event anywhere, preferably replicated storage.
Second: Name the remote event "Event" and make a local script. in the local script do the following

game.ReplicatedStorage.Event:FireServer()

Third: Make a script in serverscript service. In the script write the following

local event = game.ReplicatedStorage.Event

event.OnServerEvent:Connect(function(player)
    print(player.Name)
    --Boom!
end)
0
Looks good, am I also to just put (player.Name) in the adress of an object? (e.g. game.Players.J_98482.object, but replace my name with the name of the player that clicked on the block) J_98482 18 — 5y

Answer this question