Why is this using Player instead of Mouse?

Hey there,

I am making a building system and, am trying to make the actual placement.

This is not adjusted as i just made it to test but when i try to position the block to the Player’s mouse Target CFrame, it only returns Player

Here are the scripts:

module:

function module.place(block, mouse)
	if mouse then
		local clone = block:Clone()

		print('cloned')
		clone.Parent = workspace.BlocksPlaced
		clone.Position = mouse.CFrame
		clone.Name = "PlacedBlock"
	end
 	
	
end

server

event.OnServerEvent:Connect(function(mouse)
	print'event'
	module.place(serverStorage.Models:WaitForChild("Block"), mouse)
end)

client

local event = game.ReplicatedStorage.MouseDown
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
	
mouse.Button1Down:Connect(function()
	print'found'
	event:FireServer(mouse.Target.CFrame)
end)

I hope someone can help, thanks for reading. All replies are Appreciated!

/edit

The error that i get is:

‘CFrame is not a valid member or Player (‘Players.KieranKreates’)’

1 Like

OnServerEvent has another parameter for the player so you do

event.OnServerEvent:Connect(function(player, mouse)

I’ve edited the code to add the player to all of the RemoteEvent Events, but now i get the error

‘Target is not a valid member of Players.KieranKreates’

can you send your code that you edited?

module:

function module.place(player, block, mouse)
	if mouse.Target then
		local clone = block:Clone()

		print('cloned')
		clone.Parent = workspace.BlocksPlaced
		clone.Position = mouse.Target.CFrame
		clone.Name = "PlacedBlock"
	end
 	
	
end

script:

event.OnServerEvent:Connect(function(player, mouse)
	print'event'
	module.place(player, serverStorage.Models:WaitForChild("Block"), mouse)
end)

client:

local event = game.ReplicatedStorage.MouseDown
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
	
mouse.Button1Down:Connect(function()
	print'found'
	event:FireServer(player, mouse)
end)

you don’t have to add player to event:FireServer(), just the mouse so just do
event:FireServer(mouse)

I’ve removed the player from the :FireServer function, but i still get the same error

The code is now:

function module.place(block, mouse)
	if mouse.Target then
		local clone = block:Clone()

		print('cloned')
		clone.Parent = workspace.BlocksPlaced
		clone.Position = mouse.Target.CFrame
		clone.Name = "PlacedBlock"
	end
 	
	
end

server:

event.OnServerEvent:Connect(function(player, mouse)
	print'event'
	module.place(serverStorage.Models:WaitForChild("Block"), mouse)
end)


client:

local event = game.ReplicatedStorage.MouseDown
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
	
mouse.Button1Down:Connect(function()
	print'found'
	event:FireServer(mouse)
end)

1 Like

what was the error again? i’m confused

I just realised, the error was not the same as before.

The error was:

'ServerScriptService.BuildingModule:13: attempt to index nil with ‘Target’

apparently mouse.Target.CFrame doesn’t exist as a property, maybe use mouse.Target and possibly pass that instead of just mouse

1 Like

Thanks, that worked

I appreciate your help!

no problem, remember to mark someone’s post as a solution if it helped solve your issue :slightly_smiling_face:

Oh yeah, sorry my wifi was having problems. I tried to do it before but i got Error 502!

I have done it now.

1 Like