How to overlay part properties from script to localscript

You can write your topic however you want, but you need to answer these questions:

  1. I want to make when the player hold a tool it highlight and when click place a part and remove the highlight only the player holding the tool will see it

  2. the issue is when play with a friend if you both holding the object and then 1 player click to place the part will not highlight for the player who click but still be highlight to other player

  3. I look at devforum but i dont know i cant really find the answer

heres the code I use
local script on the tool

local WheelAndAxle = script.Parent
local UserInputService = game:GetService("UserInputService")
local WheelAndAxleRemoteEventFolder = game.ReplicatedStorage.WheelAndAxleService

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

local SecretWheelAndAxle = game.Workspace.BoxFolder
local TargetParts = {}
for _, AllBox in ipairs(SecretWheelAndAxle:GetChildren())do
	for _, Wheel in ipairs(AllBox:GetChildren()) do
	if Wheel.Name == "WheelAndAxle" then
		table.insert(TargetParts, Wheel)
		print("wheel")
		end
	end
end


local connection

WheelAndAxle.Equipped:Connect(function(input, GameProcessedEvent)
	-- Make parts visible only to this player
	for _, part in ipairs(TargetParts) do
		if part.CanCollide == false then
			part.Transparency = 0  -- Client-side visibility (others still see invisible)
			part.Highlight.Enabled = true
		end

	end
	
	if GameProcessedEvent then return end
	connection = UserInputService.InputBegan:Connect(function(input, GameProcessedEvent)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			local MouseTarget = mouse.Target
			if MouseTarget and table.find(TargetParts, MouseTarget) then
				if MouseTarget.CanCollide == false and WheelAndAxle.Name == "WheelAndAxle" then
					MouseTarget.Highlight.Enabled = false
					WheelAndAxleRemoteEventFolder.ClickWheelAndAxle:FireServer(MouseTarget)
				end
			end
		end
	end)
end)


WheelAndAxle.Unequipped:Connect(function()
	-- Hide parts
	for _, part in ipairs(TargetParts) do
		if part.CanCollide == false then
			part.Highlight.Enabled = false
			part.Transparency = 1
		end
	end
	
	-- Disconnect input
	if connection then
		connection:Disconnect()
	end
end)

and this for severscript

local ReplicatedStorage = game.ReplicatedStorage

ReplicatedStorage.WheelAndAxleService.ClickWheelAndAxle.OnServerEvent:Connect(function(Player, MouseTarget)
	if MouseTarget.Name == "WheelAndAxle" then
		print(MouseTarget)
		MouseTarget.Highlight.Enabled = false
		MouseTarget.Transparency = 0
		MouseTarget.CanCollide = true
		MouseTarget.Massless = false
	end
end)

player 1 pov when click the part


player 2 pov when player 1 click the part

player 2 pov what is it left with

but player 1 pov perfectly fine

any help would be greatful and if theres a better way to script this let me know :slight_smile:

Send a RemoteEvent to tell every client to turn off/on the highlight, it’s pretty much a replication thing.

oh thank you! I don’t why I cant even think of something this simple I feel ashamed

No need to be ashamed, everyone starts somewhere anyway.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.