How can do "MouseHoverEnter" in part cloned by localscript?

function denis()

script.Parent.BrickColor = BrickColor.new(“Really red”)

end

script.Parent.ClickDetector.MouseHoverEnter:Connect(denis)

Normal script with hoverenter(not localscript)

It seems to work well, but not on part that cloned localscript

function nirand()

local prie = game.ReplicatedStorage.reint:Clone()

prie.Parent = game.Workspace

prie.Position = game.Workspace.reint.Position + Vector3.new(0,9,0)

end

script.Parent.MouseButton1Click:Connect(nirand)

(script in imagebutton)

How can this process in part by localscript?

As far as I’m aware, you can’t.
Parts created from localscripts are not synced with the server, so clickDetectors don’t work on them.
You’ll have to launch a remoteEvent when creating the part, then create it on the server

This should be on the server, I’d guess something around these lines.

local event = game.ReplicatedStorage.ClickEvent


script.Parent.MouseButton1Click:Connect(function()
      event:FireServer(player)
end)



-- Server Script

local event = game.ReplicatedStorage.ClickEvent

event.OnServerEvent:Connect(function(player)
       local prie = game.ReplicatedStorage.reint:Clone()

       prie.Parent = game.Workspace

      prie.Position = game.Workspace.reint.Position + Vector3.new(0,9,0)
      -- optional but possible
     prie:SetNetworkOwner(player)
 

end)
1 Like

I want to make cloned part only visible to part creator.
I thought using localscript is solution, for that.

If there’s another method that part created on server can only visible to part creator, pls teach me that

What if you put this inside a local script in the part?

I have thought if something, Create the part on the server, then do FireAllClients(), then in the localscript that retrieves the event, simply check if the localplayer is the NetworkOwner, if not, set CanCollide to false and Transparency to 1
(Check for the network ownership on the server)

use
local mouse = player:getmouse()
if mouse.Target == part you want then
do the thing in local scr,ipt

Other than using RemoteEvents you can put LocalScripts inside PlayerGui or somewhere localscripts will be executed

To do a “MouseHoverEnter” event on a part cloned by a localscript, you can simply add the “MouseHoverEnter” event to the cloned part within the cloning function.

function nirand()
local prie = game.ReplicatedStorage.reint:Clone()
prie.Parent = game.Workspace
prie.Position = game.Workspace.reint.Position + Vector3.new(0,9,0)

-- Add MouseHoverEnter event to cloned part
prie.MouseHoverEnter:Connect(denis)
end

script.Parent.MouseButton1Click:Connect(nirand)```