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

Can't fire client with a remote event?

Asked by 3 years ago
--serverscript
local repstorage = game:GetService("ReplicatedStorage")
local event = repstorage.StartTimer --remotevent
local part = script.Parent
part.Touched:Connect(function()
    event:FireClient()
end)
--localscript
local repstorage = game:GetService("ReplicatedStorage")
local event = repstorage.StartTimer
event.OnClientEvent:Connect(function()
    print("hi")
end)

I get this error

Argument 1 missing or nil

What I'm doing wrong? I'm new to events.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Ok Let Me Explain What You Did Wrong Ok :)

Client Script:

local Repstorage = game:service("ReplicatedStorage") -- Gets Replicated Storage
local Event = Repstorage:WaitForChild("StartTimer") -- Use :WaitForChild() Because If The Event Has Not Been Replicated Yet Then It Wont Error
Event.OnClientEvent:Connect(function() -- Runs The Function Every Time The Event Is Fired
    print("hi") -- Prints Hi
end) -- End Of Fucntion

Server Script:

local Repstorage = game:service("ReplicatedStorage") -- Gets Replicated Storage
local Event = repstorage:WaitForChild("StartTimer") -- Use :WaitForChild() Because If The Event Has Not Been Replicated Yet Then It Wont Error
local Part = script.Parent -- The Part
Part.Touched:Connect(function(Hit) -- Hit Event
    local Player -- A Variable
    if Hit.Parent:IsA("Model") then -- Check
        Player = Hit.Parent -- Model Found
    end -- End
    if Hit.Parent.Parent:IsA("Model") then -- Check
        Player = Hit.Parent.Parent -- Model Found
    end -- End
    if Player then -- Check
    else -- Otherwise
        return -- Return
    end -- End
    if game:service("Players"):FindFirstChild(Player.Name) then -- Check
        Player = game:service("Players"):FindFirstChild(Player.Name) -- Change Variable
    else -- Otherwise
        return -- Return
    end -- End
    Event:FireClient(Player) -- Fire To The Player
end) -- End Hit Function

Edit: Forgot The Server Side.

Edit 2: Forgot To Explain Server Code.

Ad

Answer this question