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

How do I get the players name that clicked the "MainDetector" and use that in the script?

I have a script that towards the bottom says localplayer but i know a script cant use local player, so how would i find the name of the player that clicked the detector and use that instead of localplayer?

-- Variables --

	local scriptFolder = script.Parent
	local partFolder = script.Parent.Parent.PartsAndSound
	
-- Scripting --

	partFolder.Enable.MainDetector.MouseClick:Connect(function()
		partFolder.Enable.Printer:Play()
			wait(0.1)
				partFolder.Enable.MainDetector:Destroy()
					scriptFolder.isPrinting.Value = true
						wait(1)
							scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
						wait(2)
							partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
								partFolder.Enable.PrintedCash:Play()
						wait(1)
							scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
						wait(2)
							partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
							partFolder.Enable.PrintedCash:Play()
							wait(1)
							scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
						wait(2)
							partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
							partFolder.Enable.PrintedCash:Play()
							wait(1)
							scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
						wait(2)
							partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
							partFolder.Enable.PrintedCash:Play()
							partFolder.Enable.SecondaryDetector.MaxActivationDistance = 15
							wait(1)
							scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
						wait(2)
							partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
							partFolder.Enable.PrintedCash:Play()
							partFolder.Enable.SecondaryDetector.MaxActivationDistance = 15
							
							
								if scriptFolder.CP3M.Value == 15000 then
									partFolder.Enable.SecondaryDetector.MouseClick:Connect(function()
										game.Players.(PLAYERNAME).leaderstats.Money.Value = game.Players.(PLAYERNAME).leaderstats.Money.Value + 15000
											script.Parent.Parent:Destroy()
									end)
								end				
	end)
	

1 answer

Hey there, ClickDetectors returns a parameter called 'playerWhoClicked', It is the player object that has clicked the detector.

To use it properly here's an example:

partFolder.Enable.MainDetector.MouseClick:Connect(function(player) -- giving the player parameter a name, in this case player
	local playerName = player.Name -- accessing the player's Name. 
end)

7 comments

0

so this gives me the name and how exactly would i be able to plug that into the script towards the bottom?

0

at the bottom instead of doing "game.Players.(PLAYERNAME)" you just do "player"

0

this is the bottom script its telling me that the player isnt a valid member of players: if scriptFolder.CP3M.Value == 15000 then partFolder.Enable.SecondaryDetector.MouseClick:Connect(function(player) -- giving the player parameter a name, in this case player local playerName = player.Name game.Players.players.leaderstats.Money.Value = game.Players.player.leaderst

0

i told you, you dont need to do game.Players.player, you just need to do 'player'

0

player.leaderstats.Money.Value = player.leaderstats.Money.Value + 15000

0

Ok so i re checked what u said, and i was being stupid and put it in the .players, i fixed it, thanks alot for helping me ive been stuck on this for a few hours! I can finally move on to other things in the game now.

0

Awesome, good luck on developing the game

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