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

  ServerScriptService.Script:4: attempt to index nil with 'Hit'???

Trying to make a simple placement system in roblox Here is the script inside the tool.

script.Parent.Activated:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

Here is the script inside the server script service

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
	local mouse = plr:GetMouse()
	local part = Instance.new("Part", workspace)
	part.Position = mouse.Hit.p
end)

2 comments

0

You can't access a Client Instance on the Server. Pass MouseHit.P through the LocalScript.

0

But when I try: ServerScriptService.Script:3: invalid argument #3 (Vector3 expected, got Instance)

2 answers

This item must be used in a LocalScript to work as expected online.

This is a note written in the Developer Hub. Therefore, you cannot do a :GetMouse() in a normal script. I would also recommend using UserInputService because it has more functions than :GetMouse(). What you can do is read EgoMoose's placement system tutorial.

You cannot fire server from a server script. Change the tool script to a local script.

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