Player = Nil with Tool.Activated:Connect(function(Player)

I’m trying find the player so I can change the leaderstats but when I do that it returns Player as nil using Tool.Activated:Connect(function(Player)

I don’t know what I can do to find the Player that activated the tool

local Tool = script.Parent
local ToolModule = require(game.ReplicatedStorage:WaitForChild("Tools"))

local Animation = Instance.new("Animation")
Animation.AnimationId = ("rbxassetid://"..ToolModule[Tool.Name].AnimationID)

local track
local cooldown = false

Tool.Activated:Connect(function(Player)
	if cooldown == false then
		cooldown = true
		track = script.Parent.Parent:WaitForChild("Humanoid"):LoadAnimation(Animation)
		track.Priority = Enum.AnimationPriority.Action
		track:Play()
		
		wait(0.3)
		Tool.Brush.ParticleEmitter.Enabled = true
		wait(0.1)
		Tool.Brush.ParticleEmitter.Enabled = false
		wait(2)
		
		local Gain = ToolModule[Tool.Name]
		
		Player.playerstats.Backpack.Value = Player.playerstats.Backpack.Value + Gain
	
		cooldown = false
		
	else
		print("Cooldown!")
	end
	
end)

IIRC, Tool.Activated returns a mouse object, not a player object. If it is a local script, consider just using game.Players.LocalPlayer instead

Its not a local script, Is there a way I could find the player without using events?

local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)

will work if put inside the .Activated thing

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.