Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My remote event won't get called?

Asked by 5 years ago

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.

0
You cannot use OnServerEvent in a local script, try using OnClientEvent instead. 522049 152 — 5y
0
Also Server can't access PlayerGui User#19524 175 — 5y

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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!

Ad
Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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 :)

Answer this question