MouseClick on click detectors not working

I added a mouse click function to fire an event but it does not work at all, I’ve replaced the event with mouse right click and mouse hover and it does work with those events but not with mouseclick thus it means that the issue is the function itself and not my coding. This is a serious issue which I need help with.

here are the lines of code it’s a server side script in service script service:
workspace.cafe_part.cd.MouseClick:Connect(function(plr) print('clicked') game:GetService("ReplicatedStorage").client_events.cafe:FireClient(plr) plr.Character.Humanoid.WalkSpeed = 0 end)

3 Likes

There’s not enough information on this thread. You’ve provided what the server is doing but there’s nothing on what the client is doing, nor if you’ve received any console errors. What you posted isn’t the issue here and I can already tell.

2 Likes

I put together a small test place with the same exact code and it worked. It printed ‘clicked’ every time. Maybe there’s something else going on?

1 Like

This is my first post I’ll give more info. sorry about that.

I received no errors whatsoever
what the client is supposed to do is not really relevant since it doesn’t print anything (like it says in the lines of code)
either way I’ll still tell you want the client is supposed to do
its supposed to open up a UI where there’s dialogue but it can’t do that since the mouse click function is broken. :frowning:

2 Likes

I really don’t know this is the strangest issue I’ve encountered I’ve been trying to figure it out for over 2 hours I think my roblox place might be broken.

1 Like

That’s completely fine. Welcome to the DevForum, anyhow.

The client is relevant in this situation because it’s what is causing your issue. If you aren’t receiving any errors, then I suspect it has something to do with the client specifically because there’s nothing wrong with your server-side code (as attached in the OP). Seeing the client-side code and object hierarchy would be nice.

1 Like

oki doki :happy3:
`local plr = game.Players.LocalPlayer
StarterGui = game:GetService(“StarterGui”)
game:GetService(“ReplicatedStorage”).client_events.cafe.OnClientEvent:Connect(function()
for i,v in pairs (plr.PlayerGui:GetChildren()) do
if v:IsA(“ScreenGui”) then
v.Enabled = false
end
end
workspace.cafe_part.cd.MaxActivationDistance = 0
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
workspace.cafe_part.BillboardGui.Enabled = false
plr.PlayerGui.dia.Enabled = true
plr.PlayerGui.maingui.Enabled = false

local function shop()
	plr.PlayerGui.dia.Enabled = false
	plr.PlayerGui.cafe.Enabled = true
end

workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = workspace.cameras_start.cafe.Value
local final
local guipart
local lines
local persons

local random = math.random(1,3)
if random == 1 then

 guipart = 1 
	lines = {"Hey! Welcome","W-Welcome Guest","Riku don't be like that","Sorry sis I'm just s-shy","Anyways, welcome to our wonderful cafeteria","what w-would you like?"}
	final = 7
	persons = {"Mio","Riku","Mio","Riku","Mio","Riku"}
elseif random == 2 then
	guipart = 1 
	lines = {"H-H-Hello","RIKU!","AAAAAAHHHH","Hello welcome to our shop","what can I help you with?"}
	persons = {"Riku","Mio","Riku","Mio","Mio"}
	final = 6
elseif random == 3 then
	guipart = 1 
	lines = {"Hello welcome to our cafe!","W-we hope yo-u enjoy it","What would you like?"}
	persons = {"Mio","Riku","Mio"}
	final = 4
end

wait(3)
plr.PlayerGui.dia.next.Visible = false
   plr.PlayerGui.dia.Mio.Visible = false
   plr.PlayerGui.dia.Riku.Visible = false

   plr.PlayerGui.dia:FindFirstChild(persons[guipart]).Visible = true
   plr.PlayerGui.dia.TextLabel.Text = persons[guipart]
	for ii = 1 , #lines[guipart] , 1 do
		plr.PlayerGui.dia.txtline.Text = lines[guipart]:sub(1,ii)
		wait(1/15)
	wait(0.001)
	  end
	
	plr.PlayerGui.dia.next.Visible = true
	
plr.PlayerGui.dia.next.MouseButton1Down:Connect(function()
print('guipart'..guipart)
print(persons[guipart])
guipart = guipart + 1
if guipart == final then
	shop()
else

   plr.PlayerGui.dia.next.Visible = false
   plr.PlayerGui.dia.Mio.Visible = false
   plr.PlayerGui.dia.Riku.Visible = false

   plr.PlayerGui.dia:FindFirstChild(persons[guipart]).Visible = true
   plr.PlayerGui.dia.TextLabel.Text = persons[guipart]
	for ii = 1 , #lines[guipart] , 1 do
		plr.PlayerGui.dia.txtline.Text = lines[guipart]:sub(1,ii)
		wait(1/15)
	wait(0.001)
	  end
	
 plr.PlayerGui.dia.next.Visible = true

  
 end
 end)
--------------------------------------------------------
plr.PlayerGui.cafe.leave.MouseButton1Down:Connect(function()
plr.Character.Humanoid.WalkSpeed = 15
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
local plrgui = plr.PlayerGui
	plr.PlayerGui.cafe.Enabled = false
	plr.PlayerGui.maingui.Enabled = true
workspace.cafe_part.cafe.cd.MaxActivationDistance = 15
workspace.cafe_part.cafe.BillboardGui.Enabled = true
	if plrgui:FindFirstChild('HeadMasterGui') then
	plrgui:FindFirstChild('HeadMasterGui').Enabled = true
end

if plrgui:FindFirstChild('PetGui') then
	plrgui:FindFirstChild('PetGui').Enabled = true
end

if plr.PlayerGui:FindFirstChild('TouchGui') then
	plr.PlayerGui:FindFirstChild('TouchGui') .Enabled = true
end
if plrgui:FindFirstChild('Chat') then
	plrgui:FindFirstChild('Chat').Enabled = true
end
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
script.Parent:Clone().Parent = plr.PlayerGui
script.Parent:Destroy()
end)



plr.PlayerGui.cafe.buying.no.MouseButton1Down:Connect(function()
	plr.PlayerGui.cafe.buying:TweenPosition(UDim2.new(0.237, 0,1, 0), "Out", "Linear", 0.5,false)
end)

plr.PlayerGui.cafe.buying.yes.MouseButton1Down:Connect(function()
	game:GetService("ReplicatedStorage").client_events.cafe_buy:FireServer(plr.PlayerGui.cafe.item.Value,plr.PlayerGui.cafe.money.Value)
	plr.PlayerGui.cafe.buying.yes.Visible = false
	spawn(function()
		wait(3)
		plr.PlayerGui.cafe.buying.yes.Visible = true
	end)
	plr.PlayerGui.cafe.buying:TweenPosition(UDim2.new(0.237, 0,1, 0), "Out", "Linear", 0.5,false)
end)
for i,v in pairs (plr.PlayerGui.cafe.main.items:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Down:Connect(function()
			plr.PlayerGui.cafe.item.Value = v.Name
			plr.PlayerGui.cafe.money.Value = v.Value.Value
			plr.PlayerGui.cafe.buying.txt.Text = 'Would you like to buy '..v.Name.." for : "..v.Value.Value.." Star Gems?"
			plr.PlayerGui.cafe.buying:TweenPosition(UDim2.new(0.237, 0,0.333, 0), "Out", "Linear", 0.5,false)
		end)
	end
end

end)
`

For future reference, when you are supplying code, it helps to post only the parts that are relevant to the code (in this case, only what the client-side code looks like for the remote). You can also put your code in codeblocks so that it is easier to read, like so:

```lua
– your code
```


It seems that it’s your client-side code indeed that’s posing the problem. I don’t have a physical copy of your code so forgive me if anything I say is wrong or not a solution for you.

Judging by what you posted, as well as your statement on what the client is supposed to do upon receiving the signal that the server fired the event for the client

it doesn’t look as though you’ve closed the remote. Anything below the boxed line will be included as part of the remote’s scope (it’s like a script, except nothing there gets executed until the server uses FireClient).

You may want to look into your code a bit to see that you’ve properly put things where they belong. On the other hand though. If your code isn’t working, why it isn’t sending you prints is odd.

A few more questions firsthand:

  • Where is the part? Where is the ClickDetector? A picture of the object hierarchy (what you see in the Explorer menu) would be helpful.
  • Where is the script and what’s its ClassName? If it’s a LocalScript, change it to a normal Script.

the script is a normal script and it’s inside a part that’s located in workspace, I have a question is there an alternative to click detectors?? maybe I could try that and see if it works thanks for the input in the client side code :smiley:

1 Like

There are alternatives to click detectors but that’s by using the actual mouse. It’s more trouble to create that kind of custom input behaviour when ClickDetector is good enough for your case. There’s more involved if you choose not to use ClickDetectors and you shouldn’t trouble yourself with that just yet.

I have a repro if you’d like that I believe about replicates what you’re attempting to accomplish. You can download this file and explore it in Roblox Studio to see what I’m doing.

ClickerRepro.rbxl (14.7 KB)

Your code should look something like this. If you Play Solo and click the part, check your output. It should say “yes”. If this is the case, then you can stylise your code so it looks similar to what the repro has.

If this doesn’t work, it may come down to having to rewrite the code somewhere.

1 Like

Use a localscript and Mouse events.

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

Mouse.Button1Down:connect(function()
   Target = Mouse.Target
   if Target and Target.Name == "cafe_part" then
      -- Do everything here
   end
end)
2 Likes

I believe it’s his serverscript that detects the MouseClick that would be located in a part in the workspace.

The second you said that I updated my post because I didn’t see that! :stuck_out_tongue_winking_eye:

1 Like