Firing model to cilent returns as nil

module script:

local module = {}

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")

local MapStorage = ReplicatedStorage.Map:GetChildren()

module.LoadMap = function()
	local PickedMap = MapStorage[math.random(1, #MapStorage)]
	PickedMap.Parent = game.Workspace
	return PickedMap
end

module.Gamemode = function(Gamemode)
	local point = 0
	if Gamemode == "Classic" then
		local PickedMap = module.LoadMap()
		for _,player in ipairs(game.Players:GetPlayers()) do
			point += 1
			local hiddenleaderstats = player:FindFirstChild("hiddenleaderstats")
			local character = player.Character

			local Wrap = hiddenleaderstats.Wrap.Value
			local Skin = hiddenleaderstats.Skin.Value

			if game.ReplicatedStorage:WaitForChild("Karts"):WaitForChild("Wraps"):FindFirstChild(Skin):FindFirstChild(Wrap) then else warn("No skin/wrap for "..Skin.."/"..Wrap) end
			local model = game.ReplicatedStorage:WaitForChild("Karts"):WaitForChild("Wraps"):FindFirstChild(Skin):FindFirstChild(Wrap):Clone()
			
			model.Parent = workspace.Karts
			model:SetPrimaryPartCFrame(PickedMap.KartSpawners:FindFirstChild(point).CFrame)
			Remotes.Kart:FireClient(player,"Join",model)
		end
		Remotes.UI:FireAllClients("Countdown")
		task.wait(4.8)
		PickedMap.Barrier.CanCollide = false
	end
end

return module

this is the module that fires the remote to the cilent, if i dont put a task.wait, the local script returns as “nil”, even with task.wait() it sometimes doesn’t work

local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")

local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Remote = Remotes:WaitForChild("Kart")

local MainUI = script.Parent.MainUI

Remote.OnClientEvent:Connect(function(input, kart)
	if input == "Join" then
		kart.Remotes.Kart:FireServer("Join")
	elseif input == "Leave" then
		kart.Remotes.Kart:FireServer("Leave")
	end
end)

if anyone could help that’d be extremely useful
and i don’t really why this happens, it fixes if i don’t clone

Maybe the remotes on the kart haven’t loaded in yet so try:

Remote.OnClientEvent:Connect(function(input, kart)
	if input == "Join" then
		kart:WaitForChild("Remotes"):WaitForChild("Kart"):FireServer("Join")
	elseif input == "Leave" then
		kart:WaitForChild("Remotes"):WaitForChild("Kart"):FireServer("Leave")
	end
end)

Otherwise I’d print(kart) on the client and print(model) on the server to see which one is failing.

Hello, it’s because the model still hasn’t loaded for the client. I’d recommend instead firing the name of the model, then doing a WaitForChild(model_name) on the client

This means you will have to name every kart separetely from each other, a lazy solution would be doing “Wrap”…math.random(1, 2000000)

yeah i did that already but seperately

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