Attempt to index nil with "Parent"

Get an error while testing.

Attempt to index nil with "Parent"

Local Script:

local Player = game.Players.LocalPlayer
local EnterSwanEvent = game.ReplicatedStorage.Events:WaitForChild("EnterSwanEvent")
local TeleportGui = Player.PlayerGui:WaitForChild("TeleportGui")
local TweenService = game:GetService("TweenService")
local MainMap = game.Workspace:WaitForChild("MainMap")
local MapToReplace = game.ServerStorage:FindFirstChild("SwanLocationMap")

EnterSwanEvent.OnClientEvent:Connect(function()
	TweenService:Create(TeleportGui.Fade, TweenInfo.new(0.5), {BackgroundTransparency = 0}):Play()
	task.wait(0.9)
	MainMap.Parent = game.ServerStorage
	MapToReplace.Parent = game.Workspace
	for i, v in pairs(Player.Character:GetChildren()) do
		if v:IsA("BasePart") then
			v.CFrame = MapToReplace.SwanToTeleport.CFrame
		end
	end
	TweenService:Create(TeleportGui.Fade, TweenInfo.new(0.5), {BackgroundTransparency = 1}):Play()
end)

Any help is appreciated, thanks.

It means that there was an error getting either the MainMap or the MapToReplace. Check if they are really there,have loaded etc.

Doesn’t really work.

The output says:
Infinite yield possible on 'ServerStorage:WaitForChild("SwanLocationMap")

This means it’s not finding SwanLocationMap in ServerStorage. When you look at the Explorer and go into ServerStorage, is it there?

Yes, the SwanLocationMap is in the serverstorage, but the local script does not seem to find it.

That’s because LocalScripts do not have access to ServerStorage, only normal Scripts have access to ServerStorage when they’re put on the server. Try putting it in ReplicatedStorage instead and see if it works then. :slight_smile:

1 Like

Make sure to have the serverstorage variable as: game:GetService("ServerStorage")

If it’s running on the client side, then it wouldn’t have access to anything in ServerStorage to my knowledge. I know ReplicatedStorage replicates between both client and server, so both would have access to it.

Mybad, I didn’t see the “local script” under it

1 Like

It’s working now, anyways, thanks to both of you for solving.

1 Like

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