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

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

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.

1 comment

0

Please show your current code so we can further assist you.

2 answers

✓ Accepted answer

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.

3 comments

0

this should do the trick for events that already has a "playerWhoClicked" by default anyways, other than that, you can always use remoteevents.

0

you can just use player.Character

0

well, i guess that works aswell /shrug

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)

1 comment

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)

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