Im trying to make a script that helps my building script to know where you will put your block,but when i try to use the mouse variable on the function to change the block position to the mouse position,this happens:

17:15:01.736 - Workspace.Player1B.FollowMouseScript:25: attempt to index global 'Mouse' (a nil value) 17:15:01.737 - Stack Begin 17:15:01.737 - Script 'Workspace.Player1B.FollowMouseScript', Line 25 17:15:01.738 - Stack End

Here's the script

Character = game.Workspace:FindFirstChild(script.Parent.Owner.Value)
if Character then
	print ("Character Found")
end
Player = game.Players:GetPlayerFromCharacter(Character)
if Player then
	print ("Player Found")
end
Mouse = Player:GetMouse()

if Mouse then
	print ("Mouse Found")
end
function FollowMouse()
	local MouseCFrame = Player:GetMouse()
	 		local x1 = math.floor(MouseCFrame.Hit.x)
            local y1 = math.floor(MouseCFrame.Hit.y)
            local z1 = math.floor(MouseCFrame.Hit.z)
            print (x1)
            print (y1)
            print (z1)
            script.Parent.Position = Vector3.new(x1,y1,z1)
            script.Parent.Rotation = Vector3.new(0,0,0)
end
Mouse.Move:connect(FollowMouse)

function RemoveBlock(PlayerName)
	
	if PlayerName == Player.Name then
		script.Parent:Destroy()
	end
	
	
	
end
game.Players.PlayerRemoving:connect(RemoveBlock)

It only works on studio solo,multiplayer online doesn't work with it

5 comments

0

The mouse can only be accessed in a local script.

0

i know,but when i use it in a local script it just doesn't do anything

0

its the way you are getting the player, use LocalPlayer.

0

it still doesn't follow my mouse

0

i think now that i know,thanks for helping,local scripts only are activated by default on certain objects