I'm trying to make an axe and I don't know how to let my script edit bricks. Whenever I click a tree it falls down like it is supposed to but only on my screen. For my friends, it stays standing up. I know why this is happening I think.

Do I need multiple scripts for this or what?

Here is the local script I have right now:

local Tool = script.Parent.Parent

Tool.Equipped:Connect(function(mouse1)
    Mouse = mouse1
end)
	 
local function onActivation() 
	local rayDest = (Mouse.Hit.Position - script.Parent.CFrame.Position).Unit * 100 
	local ray = Ray.new(script.Parent.Position, rayDest)
	local hit,position = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
	if hit then
		if hit.Name == "Log" or hit.Name == "Trunk" then
			local treeChilds = hit.Parent:GetChildren()
			for name, child in pairs(hit.Parent:GetChildren()) do -- Looping through all of the children
	    		if child:IsA("BasePart") then -- Checking if it's a part
	        	child.BrickColor = BrickColor.Red() 
	        	child.Anchored = false
	    		end
			end
		end
	end
end
	 
Tool.Activated:Connect(onActivation)



5 comments

2

The reason for this is because you're doing it on the client. You'll need remote events to make changes replicate to the server.

0

Adding on to incapaz, as the tool is activated, fire the server on a RemoteEvent in ReplicatedStorage and then in the server script in server script service type your properties code

0

A better idea would be to, on the server side, set the network owner of the part to the player.

0

Okay, I fixed the problem

0

you can use a script inside the tool as Activated Events can be accessed on the server