Does clickdetector only work on server, its not working on client

so im making a survival game, and if u kill an animal they drop meat, but if u hover over the meat, the highlight is supposed to enable (client), and when clicked, it would fire a remote, but it only enables server side, is there another method for client or is it only for server:

local clickDetector = script.Parent

clickDetector.MouseClick:Connect(function()
	local item = "Raw Meat"
	game.ReplicatedStorage.PickUpItem:FireServer(item)
	print("why doesnt it work")
end)

clickDetector.MouseHoverEnter:Connect(function()
	script.Parent.Parent.Highlight.Enabled = true
end)

clickDetector.MouseHoverLeave:Connect(function()
	script.Parent.Parent.Highlight.Enabled = false
end)

Screenshot 2024-11-25 at 5.36.18 PM

Just use Mouse.Target in a loop and check if the target contains an “item” tag or something.
(Make sure to check the magnitude as well so the player can’t pick stuff up from across the map)

so something like this? ( i will do magnitude just an example )

while true do
	task.wait()
	if Mouse.Target == script.Parent.Parent then
		script.Parent.Parent.Highlight.Enabled = true
	else
		script.Parent.Parent.Highlight.Enabled = false
	end
end


This part may not be working, the rest works fine.
game.ReplicatedStorage.PickUpItem:FireServer(item)

Maybe check your MaxActivationDistance.

im spamming the clickdetector in game and it doesnt print

hi,

where’s the Materials folder located? the local script cannot work within workspace, you have to move it into StartPlayerScripts and detect it from there

ok lemme try doing starterplayerscripts

something like this? cuz i get an error of attempt to index nil with findfirstchildofclass:

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

while true do
	task.wait()
	if game:GetService("CollectionService"):HasTag(Mouse.Target, "Item") then
		Mouse.Target:FindFirstChildOfClass("Highlight").Enabled = true
	else
		Mouse.Target:FindFirstChildOfClass("Highlight").Enabled = false
	end
end

no

local pathToClickDetector = workspace.MyClickDetector

pathToClickDetector.MouseClick:Connect(function()
 print("haii :33")
end)

uh workspace.MyClickDetector? i removed it but before it was in the part the detector

keep the detector, just place the script that does the actual detection somewhere like StarterPlayerScripts

Worked for me as a serverscript … why wouldn’t it.

it even works for me in server, but not client

your code is not the problem ig
make sure that its a NORMAL script with runcontext set to client and not a client scripts
because client scripts donot work in workspace by default

add this script / the white script
{EF54E8C2-667D-4CC7-8B5D-2557268287C4}
and set run context to client
{A0DDDD81-08A9-4D23-B169-CEF495A40859}

1 Like

it works but would the highlight be seen by others

no you will need to send a remote event to the server to highlight it because its a local script

you can go test tab and test with local server 2+ players to make sure that it doesn’t replicate
{494FD958-06EA-4758-BF67-FF5CC18F1843}

This isn’t a local script the way it’s been wrote and if it is … that’s the problem.

ye but if i hover on one window then switch to the other, it would stop hovering ( for 2 player test )

keep every window half the screen so you can see both at the same time

ye this works thx i didnt know what runcontext was, also just asking, whats the difference between server and legacy

1 Like