How can i make this script find the player who activated the tool?
local clickable = true script.Parent.Activated:Connect(function(plr) if clickable then clickable = false plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 5 plr.leaderstats.Total.Value = plr.leaderstats.Total.Value + 1 wait(5) clickable = true end end)
Try using game.Players.LocalPlayer
? I have added a print to find the player. Basically it just finds the player name and prints it by printing plr.Name
I DON'T KNOW WHAT YOU MEAN BY: "How can i make this script find the player who activated the tool?" so I have made it print the username. And made a script you can work off.
eg.
local plr = game.Players.LocalPlayer local clickable = true script.Parent.Activated:Connect(function() if clickable then clickable = false plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 5 plr.leaderstats.Total.Value = plr.leaderstats.Total.Value + 1 print (plr.Name) --find him lol wait(5) clickable = true end end)
or work off this
local plr = game.Players.LocalPlayer local clickable = true script.Parent.Activated:Connect(function() if clickable then clickable = false plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 5 plr.leaderstats.Total.Value = plr.leaderstats.Total.Value + 1 local playerwhodidit = plr.Name --work off this wait(5) clickable = true end end)
tool.Activated
does not give you the player that activated the tool. But as already suggested by gioni01 you can get the player from the character, with the :GetPlayerFromCharacter()
method of the Players service.
local clickable = true local tool = script.Parent -- variable for the tool local Players = game:GetService("Players") tool.Activated:Connect(function() local plr = Players:GetPlayerFromCharacter(tool.Parent) if clickable then clickable = false plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 5 plr.leaderstats.Total.Value = plr.leaderstats.Total.Value + 1 wait(5) clickable = true end end)
tool.Parent
is the character model since when a tool is equipped it is parented to the character.