Help with points for kill system

I’m trying to improve my understanding of DataStoreService. I’m using a system where if you destroy an item you get a point. The item is destroyed but the point isn’t added. Any help would be much appreciated.

Server Script:

local repStor = game:GetService("ReplicatedStorage")

local FruitTool = repStor.FruitTool
local Fruit = repStor.Fruit

function Fruittool(player, Tool, hum)
	local FAnimation = script:WaitForChild("FruitAnimation")
	local FAnimationTrack = hum:LoadAnimation(FAnimation)

	FAnimationTrack:Play()

	local Points = player.leaderstats.Points.Value
	
	local HPart = Tool.HPart
	for _,v in pairs(HPart:GetChildren()) do
		v.Touched:Connect(function(hit)
			if hit.Name == "Fruit" then
				hit:Destroy()
				Points = Points + 1
			end
		end)
	end
end

FruitTool.OnServerEvent:Connect(Fruittool)

Local script:

local repStor = game:GetService("ReplicatedStorage")
local FruitTool = repStor.FruitTool
local Fruit = repStor.Fruit

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local Tool = script.Parent

Tool.Activated:Connect(function()
	local hum = player.Character:WaitForChild("Humanoid")
	FruitTool:FireServer(Tool, hum)
end)
4 Likes

well the part is touching it

not the tool

so change hit.name == "Fruit" into hit.Parent.Name == "Fruit"

1 Like

Thanks for the reply. Not really sure what you mean, could you explain? The ‘Fruit’ is one part.

change this to local Points = player.leaderstats.Points

change this to Points.Value = Points.Value+1

it should work

4 Likes

since its the part touching but the part’s name is Handle change it to

hit.Parent.Name == "Tool" -- two = if you are using an if statement
1 Like

I still don’t really understand. I want it so that when the tool touches the ‘Fruit’ the fruit is destroyed. Could you maybe make the edits to my script you are trying to explain, or are the edits too extensive?

No dude, a tool can’t touch, only parts

1 Like

Detect for when the tool’s Handle, or a part in the tool comes in contact instead- a Tool itself does not have a Touched event, and can’t come in contact physically with anything else

Responding to @FerbZides

Edit: Also, a for loop isn’t necessary for the purpose either, just check whether said part exists

1 Like

Which is why I’m using a for loop to run through a model with the tools parts inside. My original question was concerning the point system, which has now been answered. Any suggestions as to how I could streamline my script or even improve upon it are still welcome, however.

1 Like