Get points if only tool clicks player?

So, I’m making a pushing simulator experience where if they push somebody they get points but how would I go by writing that script?

This is my current script:


local tool = script.Parent
local Player = tool.Parent.Parent
local leaderstats = Player.leaderstats.Pushs -- whatever the value in leaderstat is named
tool.Activated:Connect(function()
	
	leaderstats.Value = leaderstats.Value + 1
end)

It could work, but it wouldn’t exactly be certain

To ensure that there is a leaderstats folder, call WaitForChild()

local tool = script.Parent
local Player = tool.Parent.Parent
local leaderstats = Player:WaitForChild("leaderstats"):WaitForChild("Pushs") -- whatever the value in leaderstat is named

tool.Activated:Connect(function()
	leaderstats.Value = leaderstats.Value + 1
end)

Of course this isn’t the only option, you can obtain the Player’s Character as well in order to get the Player Object (Which would probably be the better approach)

local tool = script.Parent

tool.Activated:Connect(function()
    local Player = game.Players:GetPlayerFromCharacter(tool.Parent)

    if Player then
        local leaderstats = Player:WaitForChild("leaderstats"):WaitForChild("Pushs")

	    leaderstats.Value = leaderstats.Value + 1
    end
end)
1 Like

Do this

--localscript in tool

local Mouse = game.Players.LocalPlayer:GetMouse()

script.Parent.Activated:Connect(function()
    script.Parent.RemoteEvent:FireServer(Mouse.Target)
end)

--serverscript in tool
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player,target)
    if target.Name == player.Name and target:IsA("Player") then
        player.leaderstats.pushs.Value += 1
    end
end)

It still gives points by just clicking, I want it to only give points by clicking on player

What exactly do you mean…? Like do you want the Tool to only give points when the mouse is on a different Player?