So, this is what the script is supposed to do: If a tool is equipped and you are touching an object with the tool and clicking, it will deduct the size of the thing you are touching by .1. Everything works. The only problem is that when ONE part is being touched it affects all of the other parts. How do I prevent this from happening?

--LocalScript in StarterCharacterScripts

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") 


local CanScale = false

for _, children in pairs(workspace.Stuff:GetChildren()) do
	if children.Name == "Part" then
		local trigger = children
		trigger.Touched:Connect(function(part)
   CanScale = true
end)

trigger.TouchEnded:Connect(function(part)
   CanScale = false
end)
for _, child in pairs(player.Backpack:GetChildren()) do
	if child:IsA("Tool") then
		local tool = child 
		tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
   if CanScale then
      RemoteEvent:FireServer(trigger)
   end
end)
end)
	end
end

	end
end

--Script in ServerScriptService:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Parent = ReplicatedStorage

RemoteEvent.OnServerEvent:Connect(function(plr,part)
   part.Size = part.Size - Vector3.new(.1,.1,.1)
end)

2 comments

0

You need to rethink the this code. You are just adding events every time which is what is causing your script to not work as expected.

0

Could you please help me? I have no idea where to start..