Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Do I Make It So It Only Affects The Part That Has Been Touched?

Asked by 5 years ago

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)
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. User#5423 17 — 5y
0
Could you please help me? I have no idea where to start.. SnakeInTheBoots 54 — 5y

Answer this question