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