When the gui button is clicked the server is supposed to receive a signal from a remoteEvent, which is working fine, but the accept visitor and refuse visitor functions are not working I keep getting this error: ' PrimaryPart is not a valid member of Player "Players.MOREHOURSOFFUN'
Why is this?
--Service Variables
local ls = game:GetService("Lighting")
local rs = game:GetService("ReplicatedStorage")
--Remote Events and Function Variables
local loadVisitGui = rs:FindFirstChild("loadVisitGui")
local acceptVisitor = rs:FindFirstChild("acceptVisitor")
local refuseVisitor = rs:FindFirstChild("refuseVisitor")
--NPC Variables
local visitorsFolder = rs:WaitForChild("Visitors")
local boy = visitorsFolder:WaitForChild("Boy")
local businessMan = visitorsFolder:WaitForChild("BusinessMan")
local oldMan = visitorsFolder:WaitForChild("OldMan")
--Model Variables
local door = game.Workspace.FrontHall.Front:WaitForChild("Door")
--Npc Spawn Variables
local visitorSpawn = game.Workspace:WaitForChild("visitorSpawn")
local insideHouse = game.Workspace:WaitForChild("insideHouse")
local function spawnVisitor(npc)
wait(10)
npc.Parent = game.Workspace
npc.PrimaryPart.CFrame = visitorSpawn.CFrame
wait(0.1)
door.Transparency = 1
return npc.Name
end
local function despawnVisitor(npc)
npc = npc
door.Transparency = 0
npc.PrimaryPart.CFrame = CFrame.new(Vector3.new(-40.603, 3, -17.791))
npc.Parent = rs
end
local function onAcceptVisitor(npc)
npc = npc
npc.PrimaryPart.CFrame = insideHouse.CFrame
end
local function visitorInteraction(npc)
spawnVisitor(npc)
loadVisitGui:FireAllClients(npc)
acceptVisitor.OnServerEvent:Connect(onAcceptVisitor)
refuseVisitor.OnServerEvent:Connect(despawnVisitor)
end
visitorInteraction(boy)

7 comments
i'm getting an "attempt to index nil with parent" on line 25, that's where i'm moving the npc from rs to workspace
How are you firing the server? I can't help if I can't see the client
I am firing the server when a button is clicked so for example "RemoteEvent:FireServer(npc)" so that fires when a button is clicked and is supposed to let the server know which npc they're dealing with
hello?
That's because you're calling 'spawnVisitor' when you haven't declared the NPC yet due to the Callbacks not being invoked by a signal pickup at the time.
nicely caught, thanks @Ziffixture
hopefully fixed...