Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My remote event won't get called?

Alright, so I have one Local Script, and one script. A Script indentifies that a clickdetector is being used and sends out a remote event to the local script to bring a GUI up. I think its not sending it, any help?

Codes are down below.

Script:

local clickdetector = game.Workspace.Car.ClickDetector
clickdetector.MouseClick:Connect(function()
	game.Workspace.GuiClicker:FireServer()
	
	end)

Local Script:

local debounce = false

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local GuiClicker = game.Workspace.GuiClicker
local playerGui = player:WaitForChild("PlayerGui")


game.Workspace.GuiClicker.OnServerEvent:Connect(function()
	

    if debounce == false then
        playerGui.InfoPanel.ScrollingFrame.Visible = true
        playerGui.InfoPanel.ScrollingFrame:TweenPosition(UDim2.new(0.5, -250,0.5, -200, 'Out', 'Bounce', 1))
        debounce = true
    else
        playerGui.InfoPanel.ScrollingFrame:TweenPosition(UDim2.new(-0.5, -250,0.5, -200, 'Out', 'Bounce', 1))

        debounce = false
    end
end)

Thanks for any help.

Best regards, Car00071.

2 comments

0

You cannot use OnServerEvent in a local script, try using OnClientEvent instead.

0

Also Server can't access PlayerGui

2 answers

✓ Accepted answer

You have your methods and events the wrong way around. When a server script is firing a remote event to a local script, you should use :FireClient() with the player whose client you want to fire in the brackets. So, as the player is the first parameter of MouseClick in ClickDetectors, you can do something like:

clickdetector.MouseClick:Connect(function(Plr)
	game.ReplicatedStorage.GuiClicker:FireClient(Plr)
end)

(It is also better to use ReplicatedStorage instead of Workspace for remotes, so I changed that too).

Then, in the local script, you will use OnClientEvent instead of OnServerEvent.

However, you can actually achieve this without the use of ClickDetectors or RemoteEvents. If you use the player's Mouse in a local script, you can get the mouse Target on Button1Down to see if the player is clicking the part:

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

Mouse.Button1Down:Connect(function() --Mouse was clicked:
	local Targ = Mouse.Target
	if Targ then --if the mouse is hovering over a part:
		print("Mouse has clicked " .. Targ.Name)
		if Targ == game.Workspace.Car then
			--player has clicked the "Car" part in workspace
		end
	end
end)

Hope this helps!

When you are sending a signal to a client, you must use the FireClient() function. To listen for these events, use OnClientEvent.

Since you are sending information from a server to a client, you should use FireClient.

Hope this helps :)

This discussion is preserved as it was. New answers, comments, and votes are closed.