Yeah so i wanted to create a Spawn GUI for trains. When touching a part, the GUI gets copied over to the player’s playergui. But when the Player effectively presses the Spawn button, the remote event gets triggered, a error gets printed attempt to call a nil value. I’m trying to use a String as Argument.
The Script which gets fired trough the RemoteEvent is following:
local Lightning = game:GetService("Lighting")
local TrainType = nil
local player = nil
local RemoteEvent = script.Parent.SpawnPlace1
-- list all models
local HK4CarriagesModel = game.Lighting["Ge 4/4 II Road Edition"]
local HK8CarriagesModel = game.Lighting["Ge 4/4 II Road Edition Blue"]
local function SpawnTrain(player, TrainType)
print(typeof(player), typeof(TrainType))
if TrainType == "HK4Carriages" then
local CopyHK4 = HK4CarriagesModel:Clone()
CopyHK4.Parent = game.Workspace
elseif TrainType == "HK8Carriages" then
local CopyHK8 = HK8CarriagesModel:Clone()
CopyHK8.Parent = game.Workspace
end
end
RemoteEvent.OnServerEvent:Connect(SpawnTrain(player,TrainType))
local SpawnEvent = game.Workspace.CreateGUI.SpawnPlace1
local SpawnButton = script.Parent
local GUI = script.Parent.Parent.Parent.Parent.Parent
local player = nil
local function FireEvent()
SpawnEvent:FireServer(player, "HK8Carriages")
GUI:Destroy()
end
SpawnButton.MouseButton1Click:Connect(FireEvent)
thats the second of the 2 scripts, they are pretty similar, just a few variables changed
local SpawnEvent = game.Workspace.CreateGUI.SpawnPlace1
local SpawnButton = script.Parent
local GUI = script.Parent.Parent.Parent.Parent.Parent
local player = nil
local function FireEvent()
SpawnEvent:FireServer("HK8Carriages")
GUI:Destroy()
end
SpawnButton.MouseButton1Click:Connect(FireEvent)
I found another problem in your code and I fixed it.
local Lightning = game:GetService("Lighting")
local TrainType = nil
local player = nil
local RemoteEvent = script.Parent.SpawnPlace1
-- list all models
local HK4CarriagesModel = game.Lighting["Ge 4/4 II Road Edition"]
local HK8CarriagesModel = game.Lighting["Ge 4/4 II Road Edition Blue"]
local function SpawnTrain(player, TrainType)
print(typeof(player), typeof(TrainType))
if TrainType == "HK4Carriages" then
local CopyHK4 = HK4CarriagesModel:Clone()
CopyHK4.Parent = game.Workspace
elseif TrainType == "HK8Carriages" then
local CopyHK8 = HK8CarriagesModel:Clone()
CopyHK8.Parent = game.Workspace
end
end
RemoteEvent.OnServerEvent:Connect(SpawnTrain)
You’re connecting your OnServerEvent within the parameters of the SpawnTrain function on the Server’s Side, you only need to call it by it’s own function without any parameters:
local Lightning = game:GetService("Lighting")
local TrainType = nil
local player = nil
local RemoteEvent = script.Parent.SpawnPlace1
-- list all models
local HK4CarriagesModel = game.Lighting["Ge 4/4 II Road Edition"]
local HK8CarriagesModel = game.Lighting["Ge 4/4 II Road Edition Blue"]
local function SpawnTrain(player, TrainType)
print(typeof(player), typeof(TrainType))
if TrainType == "HK4Carriages" then
local CopyHK4 = HK4CarriagesModel:Clone()
CopyHK4.Parent = game.Workspace
elseif TrainType == "HK8Carriages" then
local CopyHK8 = HK8CarriagesModel:Clone()
CopyHK8.Parent = game.Workspace
end
end
RemoteEvent.OnServerEvent:Connect(SpawnTrain) -- Here is where the error lies