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

RemoteEvent giving problems with FireClient?

Asked by 5 years ago

I tried after getting some help with another script to get access to a player's playergui. I used a remote event, but it didn't work though.

I created a first local script where I wrote:

local players = game:GetService("Players")
local mouse = game.Players.LocalPlayer:GetMouse()
local event = game.ReplicatedStorage.RemoteEvent

mouse.KeyDown:connect(function(k)
k = k:lower()
if k == 'z' then
     game.ReplicatedStorage.RemoteEvent:FireClient()
end
end)

Yes I know KeyDown is deprecated, please just help me. Here, I placed this local script where I Fire the Event in a ScreenGui in StarterGui.

-- Then I put another server script into ServerScriptService where I write:

local event = game.ReplicatedStorage.RemoteEvent
local players = game:GetService("Players")
local mouse = game.Players.LocalPlayers:GetMouse()
local event = game.ReplicatedStorage.RemoteEvent

event.OnServerEvent:Connect(function(plr)
    local target = mouse.Target
    local humanoid = target.Parent:FindFirstChild("Humanoid")
    print("Hello")
    if humanoid then
        print("Humanoid trovato bae")
        local character = humanoid.Parent
        local nomeplayer = players:GetPlayerFromCharacter(character)
        print(nomeplayer)
        local playergui = nomeplayer:FindFirstChild("Playergui")
        print(playergui)
    end
end)

The error is in the first localscript, in "FireClient" line, and it gives me Argument 1 missing or nil. What should I write?

0
At line 16 of the second Script, I noticed the error "Playergui" and that must be written "PlayerGui", and it still doesn't work. Fixer1987 95 — 5y
0
where did you exactly put the local script? CjayPlyz 643 — 5y
0
In a screengui in Startergui. Fixer1987 95 — 5y

2 answers

Log in to vote
0
Answered by
amanda 1059 Moderation Voter
5 years ago
Edited 5 years ago

Hello there!

On your client side script, you need to put FireServer instead of FireClient, as you are sending a message to the Server!

Next, you should be handling anything to do with anybody's PlayerGui in a LocalScript, regardless of remotes.

EDIT:

From what I understand, you are trying to remove the scripts from someone elses playergui, whenever you put your mouse on them and press Z.

To do this, you need to bounce from one client, to the server, to another client using RemoteEvents. Your current setup will not work at all, as the mouse and the LocalPlayer are things that can only be accessed locally.

--

Client:

local repstore = game:GetService("ReplicatedStorage")
local deleteGUI = repstore.deleteGUI

local uis = game:GetService("UserInputService")

local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local gui = player:WaitForChild("PlayerGui")

uis.InputBegan:Connect(function(obj)
    if obj.KeyCode == Enum.KeyCode.Z then
        local target = mouse.Target
        if target then
            local target_player = players:GetPlayerFromCharacter(target.Parent)
            if target_player then
                deleteGUI:FireServer(target_player)
            end
        end
    end
end)

deleteGUI.OnClientEvent:Connect(function()
    for _, child in pairs(gui:GetChildren()) do
        if child:IsA("LocalScript") then
            child:Destroy()
        end
    end
end)

SERVER:

local repstore = game:GetService("ReplicatedStorage")
local deleteGUI = repstore.deleteGUI

deleteGUI.OnServerEvent:Connect(function(player, target_player)
    deleteGUI:FireClient(target_player)
end)
0
I have answered and modified what you said to modify, still not working. Fixer1987 95 — 5y
0
Do you have a new error message? You should edit your original post to show your updated code. amanda 1059 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I'll explain it basically.

I'd like to Disable other people's Scripts in their PlayerGui when I click the hotkey Z. I first used the Mouse stuff like Target et cetera. Then I verified if the person was an humanoid. And the last but not least to disable their script in their playergui.

Answer this question