This remotefunction returns a nil value despite the fact that I specified it to return a vector3. Why is this? The error is: Attempt to index nil with “position” line 8. Server script. I printed raycastResult on the server script and it printed nil. I printed it on the client script and it successfully printed the vector3 I wanted. I left most of the client script out to keep things simpler as it works fine.
Client:
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
wait()
remoteEvent:FireServer()
remoteFunction.OnClientInvoke = function(player)
return raycastResult
end
IsSpawned = true
militiaclone:Destroy()
end
end)
end
end
end)
Server:
remoteEvent.OnServerEvent:Connect(function(player)
local remoteFunction = game:GetService("ReplicatedStorage").GetMilitiaCloneRemoteFunction
local raycastResult = remoteFunction:InvokeClient(player)
local militiaclone = game:GetService("ReplicatedStorage").Militia:Clone()
local x = raycastResult.Position.X
local y = raycastResult.Position.Y + 2
local z = raycastResult.Position.Z
local rayCFrame = CFrame.new(x, y, z)
militiaclone:SetPrimaryPartCFrame(rayCFrame)
militiaclone.Parent = workspace
militiaclone:WaitForChild("MilitiaScript").Disabled = false
end)