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

Can't fire client with a remote event?

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

✓ Accepted answer

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.

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