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

How would I get the local player from a script, not a local script?

I made a script that has a bunch of global's and I want to know if it is possible to get the player from a regular script because, my script works in a regular script only and doesn't in a local but, I am using local player, so Idk where to start.. Any help..?

3 comments

0

You can't use LocalPlayer in a server script because server scripts can't do anything related to the client.

0

You cannot. How would it know what player you want?

0

you can use remoteevents or other events to get the player you want

2 answers

✓ Accepted answer

You get the player when you use Events. to get the player from the Touched event, you do:

brick.Touched:Connect(function(limb) -- Touched returns the part that touched "brick"
	local player = game.Players:GetPlayerFromCharacter(limb.Parent)
	if player then
		player.Character:BreakJoints() -- kills character
		player.leaderstats.Points.Value = 1000 -- sets value to 1000 
	end
end)

to get the player from a ClickDetector, do:

ClickDetector.MouseClick:Connect(function(player) -- MouseClick returns the player that clicked
	player.Character:BreakJoints()
	player.leaderstats.Points.Value = 1000
end)

note that the arguments can be named anything

3 comments

0

I know the touched and click detector stuff... All i needed really was the character stuff

0

AND THANK YOU FOR ADDING POINTS

0

Now gotta check if it works in a server

Short answer: nope.

Long answer: Since normal scripts are made to act in the server,there is no way a script can get the local player. Only local scripts can do that because they are made to act in the client.

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