Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"X is not valid member of Player" - Why does this happen, and how to fix?

So while I was making a Building setup (Mouse localscript, gui, remoteevents, and a script), this error was given to me. Here is the Localscript depended on for creating the blocks, and handles the ghost block:

local Players = game:GetService("Players")
local BuildEvent = game.ReplicatedStorage:WaitForChild("BuildyBuildy")

local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
local Mode = script.Parent.Mode

function roundVector(vector, unit)
	return vector - Vector3.new(vector.X%unit, vector.Y%unit, vector.Z%unit)
end

local hintblock = Instance.new("Part")
mouse.TargetFilter = hintblock
hintblock.Size = Vector3.new(4,4,4)
hintblock.Transparency = 0.7
hintblock.Anchored = true
hintblock.CanCollide = false
hintblock.Parent = game.Workspace

mouse.Move:Connect(function()
	if script.Parent.Mode.Value == 1 then
		local Rpos = roundVector(mouse.Hit.p,4)
		hintblock.Position = Rpos
		hintblock.Parent = game.Workspace
	else
		hintblock.Parent = script.Parent
	end
end)

mouse.Button1Down:Connect(function()
	if Mode.Value == 0 then
		return
	elseif Mode.Value == 1 then
		local pos = mouse.Hit.p
		BuildEvent:FireServer(pos)
		print("Requesting server to build.")
	end
end)

And here is the script in ServerScriptService, depended on for making the blocks appear on demand of the local script:

local BuildingEvent = game.ReplicatedStorage:WaitForChild("BuildyBuildy")

function roundVector(vector, unit)
	return vector - Vector3.new(vector.X%unit, vector.Y%unit, vector.Z%unit)
end

BuildingEvent.OnServerEvent:Connect(function(MouseLocation)
	local newpart = Instance.new("Part")
	local RoundedPos = roundVector(MouseLocation,4)
	newpart.Position = RoundedPos
	newpart.Size = Vector3.new(4,4,4)
	newpart.TopSurface = Enum.SurfaceType.Smooth
	newpart.BottomSurface = Enum.SurfaceType.Smooth
	newpart.Color = Color3.fromRGB(50,225,50)
	newpart.Parent = game.Workspace
end)

Does anyone know where and why the error: "X is not valid member of Player" appears? Thanks in advance.

Edit: Error appeared when I tried to execute the build event, because of roundVector() at ServerScriptService.

1 answer

✓ Accepted answer

the first variable that server side recieved from RemoteEvent is Player so your problem is here.

BuildingEvent.OnServerEvent:Connect(function(MouseLocation)

Your first variable( MousLocation ) will be Player.

Fix:

BuildingEvent.OnServerEvent:Connect(function(player, MouseLocation)

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.