Argument 1 or missing nil?

Im making a teleport pad that if you step on it, it makes a loading screen. when i tried this i got an error, which was “Argument 1 or missing nil” im not the greatest at programming. help would be awesome

How it fires

script.Parent.Touched:Connect(function(prt)
	if prt.Parent:FindFirstChild('Humanoid') then
game.ReplicatedFirst.load:FireClient()
	end	
	end)

What it fires

Tween=game:GetService("TweenService")
game.ReplicatedFirst.load.OnClientEvent:Connect(function()

script.Parent.FrameLoad.Visible = true
Tween:Create(script.Parent.FrameLoad,TweenInfo.new(1),{BackgroundTransparency = 0}):Play()
Tween:Create(script.Parent.FrameLoad.TextLabel,TweenInfo.new(1),{TextTransparency = 0}):Play()
wait(1)
Tween:Create(script.Parent.FrameLoad.TextLabelt,TweenInfo.new(3),{TextTransparency = 0}):Play()
end)

:FireClient() requires you to put in a player peramater. You can do this by the following. You could also use :FireAllClients(), which would effect all players, but I don’t think thats what you want to use here.

script.Parent.Touched:Connect(function(prt)
	if prt.Parent:FindFirstChild('Humanoid') == nil then
		return --Stops the function if there is no humanoid
	end
	local player = game:GetService("Players"):GetPlayerFromCharacter(prt.Parent) --Finds to see if the character is a player
	if player == nil then
		return --Stops the function if the character is not a player's character
	end
	game.ReplicatedFirst.load:FireClient(player) --You need to put in a specific player when using :FireClient()
end)

Also, added “t” by misteak at the end of .TextLabel on last line

Tween:Create(script.Parent.FrameLoad.TextLabel,TweenInfo.new(3),{TextTransparency = 0}):Play()
end)

I hope this helps!

t was meant to be there because it was another textlabel

My misteak! Did the first part work for you though?

just tested it but it doesnt seem to make the loading screen appear

Here’s the thing, when you fire client, the client might not recieve the message for several reasons.

image

On the server script, you need to wait for a response, and sometimes it requires multiple pings.

local function fire()
   remote:FireClient() remote.OnServerEvent:Wait() return "ok"
end
 local ping
repeat ping = fire() until ping == "ok"

When the client’s script loads, they’ll recieve the signal for sure if they have a good connection Edit: this example was wrong and doesn’t work lol but a coroutine with this function would properly hook the connection

May i ask, why is the event in replicatedfirst? Also in every FireClient, a player argument is needed.

script.Parent.Touched:Connect(function(__TOUCHED)
    local __PLAYER = game:GetService("Players"):GetPlayerFromCharacter(__TOUCHED.Parent)
      if __PLAYER ~= nil then
          game.ReplicatedFirst.load:FireClient(__PLAYER)
      end
end)
1 Like

What this does is that if the player exists, stop the function. This doesn’t really make sense it should be like this.

local player = game:GetService("Players"):GetPlayerFromCharacter(prt.Parent)
if player then
	game.ReplicatedFirst.load:FireClient(player)
end

Sorry! I forgot the == nil part.

i forgot were to put remotes, but i just said screw it and put it in replicatedfirst

Events should always be in replicatedstorage.
BindableEvents in ServerStorage.

i just tested this and it worked, thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.